Skip to content

Commit

Permalink
Added clear() to allow discarding ByteBuffer contents
Browse files Browse the repository at this point in the history
the allocated memory is retained for reuse
  • Loading branch information
dktapps committed Feb 5, 2024
1 parent 688806d commit 49974ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,15 @@ BYTE_BUFFER_METHOD(trim) {
}
}

BYTE_BUFFER_METHOD(clear) {
zend_parse_parameters_none_throw();

auto object = BYTE_BUFFER_THIS();
object->read_offset = 0;
object->write_offset = 0;
object->used = 0;
}

BYTE_BUFFER_METHOD(__serialize) {
zend_parse_parameters_none_throw();

Expand Down
6 changes: 6 additions & 0 deletions stubs/BaseByteBuffer.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public function reserve(int $length) : void{}
*/
public function trim() : void{}

/**
* Clears all data from the buffer. The memory used is retained
* as reserved memory.
*/
public function clear() : void{}

public function __serialize() : array{}

public function __unserialize(array $data) : void{}
Expand Down
6 changes: 5 additions & 1 deletion stubs/BaseByteBuffer_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 7cd1dd363517d6bc01b82e50e5dc8e16c3ac569b */
* Stub hash: e4cd03e67587e5cd47862bdb22a4f9ef22e24367 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_pmmp_encoding_BaseByteBuffer___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, buffer, IS_STRING, 0, "\"\"")
Expand Down Expand Up @@ -38,6 +38,8 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_pmmp_encoding_BaseByteBuffer_trim, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_pmmp_encoding_BaseByteBuffer_clear arginfo_class_pmmp_encoding_BaseByteBuffer_trim

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_pmmp_encoding_BaseByteBuffer___serialize, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

Expand All @@ -60,6 +62,7 @@ ZEND_METHOD(pmmp_encoding_BaseByteBuffer, getUsedLength);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, getReservedLength);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, reserve);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, trim);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, clear);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, __serialize);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, __unserialize);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, __debugInfo);
Expand All @@ -78,6 +81,7 @@ static const zend_function_entry class_pmmp_encoding_BaseByteBuffer_methods[] =
ZEND_ME(pmmp_encoding_BaseByteBuffer, getReservedLength, arginfo_class_pmmp_encoding_BaseByteBuffer_getReservedLength, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, reserve, arginfo_class_pmmp_encoding_BaseByteBuffer_reserve, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, trim, arginfo_class_pmmp_encoding_BaseByteBuffer_trim, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, clear, arginfo_class_pmmp_encoding_BaseByteBuffer_clear, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, __serialize, arginfo_class_pmmp_encoding_BaseByteBuffer___serialize, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, __unserialize, arginfo_class_pmmp_encoding_BaseByteBuffer___unserialize, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, __debugInfo, arginfo_class_pmmp_encoding_BaseByteBuffer___debugInfo, ZEND_ACC_PUBLIC)
Expand Down

0 comments on commit 49974ff

Please sign in to comment.