optimize
This commit is contained in:
@@ -584,7 +584,7 @@ class APIConnection : public APIServerConnection {
|
||||
|
||||
DeferredBatch() {
|
||||
// Pre-allocate capacity for typical batch sizes to avoid reallocation
|
||||
items.reserve(16);
|
||||
items.reserve(8);
|
||||
}
|
||||
|
||||
// Add item to the batch
|
||||
|
||||
@@ -1108,15 +1108,6 @@ APIError APIPlaintextFrameHelper::write_protobuf_packets(ProtoWriteBuffer buffer
|
||||
return write_raw_(this->reusable_iovs_.data(), this->reusable_iovs_.size());
|
||||
}
|
||||
|
||||
uint8_t APIPlaintextFrameHelper::calculate_header_footer_size(uint16_t message_type, uint16_t payload_len) {
|
||||
// Calculate varint sizes (actual encoding, not padded)
|
||||
uint8_t size_varint_len = api::ProtoSize::varint(static_cast<uint32_t>(payload_len));
|
||||
uint8_t type_varint_len = api::ProtoSize::varint(static_cast<uint32_t>(message_type));
|
||||
|
||||
// Plaintext header + footer size (without padding): indicator(1) + size_varint + type_varint + footer(0)
|
||||
return 1 + size_varint_len + type_varint_len + frame_footer_size_;
|
||||
}
|
||||
|
||||
#endif // USE_API_PLAINTEXT
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -106,8 +106,6 @@ class APIFrameHelper {
|
||||
virtual uint8_t frame_header_padding() = 0;
|
||||
// Get the frame footer size required by this protocol
|
||||
virtual uint8_t frame_footer_size() = 0;
|
||||
// Calculate the actual header + footer size (without padding) sent over wire for a given message
|
||||
virtual uint8_t calculate_header_footer_size(uint16_t message_type, uint16_t payload_len) = 0;
|
||||
// Check if socket has data ready to read
|
||||
bool is_socket_ready() const { return socket_ != nullptr && socket_->ready(); }
|
||||
|
||||
@@ -207,11 +205,6 @@ class APINoiseFrameHelper : public APIFrameHelper {
|
||||
uint8_t frame_header_padding() override { return frame_header_padding_; }
|
||||
// Get the frame footer size required by this protocol
|
||||
uint8_t frame_footer_size() override { return frame_footer_size_; }
|
||||
// Calculate the actual header + footer size (without padding) for Noise protocol
|
||||
uint8_t calculate_header_footer_size(uint16_t message_type, uint16_t payload_len) override {
|
||||
// Noise: fixed 3 byte header (indicator + 2-byte size) + 16 byte MAC
|
||||
return 3 + frame_footer_size_;
|
||||
}
|
||||
|
||||
protected:
|
||||
APIError state_action_();
|
||||
@@ -256,8 +249,6 @@ class APIPlaintextFrameHelper : public APIFrameHelper {
|
||||
uint8_t frame_header_padding() override { return frame_header_padding_; }
|
||||
// Get the frame footer size required by this protocol
|
||||
uint8_t frame_footer_size() override { return frame_footer_size_; }
|
||||
// Calculate the actual header + footer size (without padding) for Plaintext protocol
|
||||
uint8_t calculate_header_footer_size(uint16_t message_type, uint16_t payload_len) override; // Implemented in .cpp
|
||||
|
||||
protected:
|
||||
APIError try_read_frame_(ParsedFrame *frame);
|
||||
|
||||
Reference in New Issue
Block a user