Skip to content

Commit b80837a

Browse files
Alex Snastmeta-codesync[bot]
authored andcommitted
Modernize HeaderChannel compression config handling
Summary: Improve efficiency and code clarity in HeaderChannel's compression configuration. Use move semantics to avoid unnecessary copies when setting compression config, mark preprocessHeader as const-correct since it doesn't modify the channel's state, and simplify codec initialization using emplace() pattern. Reviewed By: praihan Differential Revision: D89765894 fbshipit-source-id: bfd75be8df51d7299f68290b8e94ac9452d0c8a8
1 parent b7c9591 commit b80837a

3 files changed

Lines changed: 13 additions & 19 deletions

File tree

third-party/thrift/src/thrift/lib/cpp/transport/THeader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class THeader final {
365365
StringToStringMap& persistentReadHeaders);
366366

367367
void setDesiredCompressionConfig(CompressionConfig compressionConfig) {
368-
c_.compressionConfig_ = compressionConfig;
368+
c_.compressionConfig_ = std::move(compressionConfig);
369369
}
370370

371371
folly::Optional<CompressionConfig> getDesiredCompressionConfig() const {

third-party/thrift/src/thrift/lib/cpp2/async/HeaderChannel.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void HeaderChannel::addRpcOptionHeaders(
6161
}
6262

6363
void HeaderChannel::preprocessHeader(
64-
apache::thrift::transport::THeader* header) {
64+
apache::thrift::transport::THeader* header) const {
6565
header->mutableWriteHeaders().insert(
6666
persistentWriteHeaders_.begin(), persistentWriteHeaders_.end());
6767

@@ -77,23 +77,18 @@ void HeaderChannel::preprocessHeader(
7777

7878
if (!header->getDesiredCompressionConfig()) {
7979
apache::thrift::CompressionConfig compressionConfig;
80-
switch (transform) {
81-
case transport::THeader::ZLIB_TRANSFORM: {
82-
apache::thrift::CodecConfig codec;
83-
codec.zlibConfig() = apache::thrift::ZlibCompressionCodecConfig();
84-
compressionConfig.codecConfig() = codec;
80+
switch (auto&& codec = compressionConfig.codecConfig().emplace();
81+
transform) {
82+
case transport::THeader::ZLIB_TRANSFORM:
83+
codec.zlibConfig().emplace();
8584
break;
86-
}
87-
case transport::THeader::ZSTD_TRANSFORM: {
88-
apache::thrift::CodecConfig codec;
89-
codec.zstdConfig() = apache::thrift::ZstdCompressionCodecConfig();
90-
compressionConfig.codecConfig() = codec;
85+
case transport::THeader::ZSTD_TRANSFORM:
86+
codec.zstdConfig().emplace();
9187
break;
92-
}
9388
default:
9489
LOG(DFATAL) << "Unsupported transform: " << transform;
9590
}
96-
header->setDesiredCompressionConfig(compressionConfig);
91+
header->setDesiredCompressionConfig(std::move(compressionConfig));
9792
}
9893
}
9994
if (loggingContext_) {

third-party/thrift/src/thrift/lib/cpp2/async/HeaderChannel.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ namespace apache::thrift {
2727
*/
2828
class HeaderChannel {
2929
public:
30-
HeaderChannel() {}
31-
3230
void addRpcOptionHeaders(
3331
apache::thrift::transport::THeader* header, const RpcOptions& rpcOptions);
3432

@@ -44,14 +42,15 @@ class HeaderChannel {
4442
loggingContext_ = std::move(loggingContext);
4543
}
4644

47-
const transport::THeader::StringToStringMap& getPersistentWriteHeaders() {
45+
const transport::THeader::StringToStringMap& getPersistentWriteHeaders()
46+
const {
4847
return persistentWriteHeaders_;
4948
}
5049

51-
void preprocessHeader(apache::thrift::transport::THeader* header);
50+
void preprocessHeader(apache::thrift::transport::THeader* header) const;
5251

5352
protected:
54-
virtual ~HeaderChannel() {}
53+
virtual ~HeaderChannel() = default;
5554

5655
virtual bool clientSupportHeader() { return true; }
5756

0 commit comments

Comments
 (0)