markjm commented on code in PR #3596:
URL: https://github.com/apache/thrift/pull/3596#discussion_r3407611104


##########
lib/py/src/ext/types.h:
##########
@@ -131,8 +132,48 @@ typedef PyObject EncodeBuffer;
 #else
 extern const char* refill_signature;
 struct EncodeBuffer {
-  std::vector<char> buf;
-  size_t pos;
+  char* data;
+  size_t size;
+  size_t capacity;
+
+  EncodeBuffer() : data(nullptr), size(0), capacity(0) {}
+
+  ~EncodeBuffer() {
+    if (data) {
+      free(data);
+    }
+  }
+
+  bool init(size_t initial_capacity) {
+    data = static_cast<char*>(malloc(initial_capacity));
+    if (!data) {
+      return false;
+    }
+    size = 0;
+    capacity = initial_capacity;
+    return true;
+  }

Review Comment:
   thanks bot



##########
lib/py/src/ext/types.h:
##########
@@ -131,8 +132,48 @@ typedef PyObject EncodeBuffer;
 #else
 extern const char* refill_signature;
 struct EncodeBuffer {
-  std::vector<char> buf;
-  size_t pos;
+  char* data;
+  size_t size;
+  size_t capacity;
+
+  EncodeBuffer() : data(nullptr), size(0), capacity(0) {}
+
+  ~EncodeBuffer() {
+    if (data) {
+      free(data);
+    }
+  }
+
+  bool init(size_t initial_capacity) {
+    data = static_cast<char*>(malloc(initial_capacity));
+    if (!data) {
+      return false;
+    }
+    size = 0;
+    capacity = initial_capacity;
+    return true;
+  }
+
+  bool ensure(size_t additional) {
+    size_t needed = size + additional;
+    if (needed <= capacity) {
+      return true;
+    }
+
+    size_t new_capacity = capacity == 0 ? needed : capacity;
+    while (new_capacity < needed) {
+      new_capacity *= 2;
+    }
+
+    char* new_data = static_cast<char*>(realloc(data, new_capacity));
+    if (!new_data) {
+      return false;
+    }
+
+    data = new_data;
+    capacity = new_capacity;
+    return true;
+  }

Review Comment:
   thanks bot



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to