Skip to content

Commit 8755a98

Browse files
committed
Remove useless template parameter
1 parent 05da25a commit 8755a98

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

encoding.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ struct VarIntConstants {
179179
static const unsigned char MSB_MASK = static_cast<unsigned char>(1u << BITS_PER_BYTE);
180180
};
181181

182-
template<size_t TYPE_BITS, typename TValue>
182+
template<typename TValue>
183183
static inline bool readUnsignedVarInt(zend_string *bytes, size_t used, size_t& offset, TValue &result) {
184+
const auto TYPE_BITS = sizeof(TValue) * CHAR_BIT;
184185
result = 0;
185186
for (unsigned int shift = 0; shift < TYPE_BITS; shift += VarIntConstants::BITS_PER_BYTE) {
186187
if (offset >= used) {
@@ -199,10 +200,10 @@ static inline bool readUnsignedVarInt(zend_string *bytes, size_t used, size_t& o
199200
return false;
200201
}
201202

202-
template<size_t TYPE_BITS, typename TUnsignedValue, typename TSignedValue>
203+
template<typename TUnsignedValue, typename TSignedValue>
203204
static inline bool readSignedVarInt(zend_string* bytes, size_t used, size_t& offset, TSignedValue& result) {
204205
TUnsignedValue unsignedResult;
205-
if (!readUnsignedVarInt<TYPE_BITS, TUnsignedValue>(bytes, used, offset, unsignedResult)) {
206+
if (!readUnsignedVarInt<TUnsignedValue>(bytes, used, offset, unsignedResult)) {
206207
return false;
207208
}
208209

@@ -313,8 +314,9 @@ static zend_string* writeFixedSizeType(zend_string* buffer, size_t& offset, TVal
313314
return buffer;
314315
}
315316

316-
template<size_t TYPE_BITS, typename TValue>
317+
template<typename TValue>
317318
static inline zend_string* writeUnsignedVarInt(zend_string* buffer, size_t& offset, TValue value) {
319+
const auto TYPE_BITS = sizeof(TValue) * CHAR_BIT;
318320
char result[VarIntConstants::MAX_BYTES<TYPE_BITS>];
319321

320322
TValue remaining = value;
@@ -343,15 +345,15 @@ static inline zend_string* writeUnsignedVarInt(zend_string* buffer, size_t& offs
343345
return buffer;
344346
}
345347

346-
template<size_t TYPE_BITS, typename TUnsignedType, typename TSignedType>
348+
template<typename TUnsignedType, typename TSignedType>
347349
static inline zend_string* writeSignedVarInt(zend_string* buffer, size_t& offset, TSignedType value) {
348350
TUnsignedType mask = 0;
349351
if (value < 0) {
350352
//we don't know the type of TUnsignedType here, can't use ~0 directly (the compiler will optimise this anyway)
351353
mask = ~mask;
352354
}
353355

354-
return writeUnsignedVarInt<TYPE_BITS, TUnsignedType>(buffer, offset, (static_cast<TUnsignedType>(value) << 1) ^ mask);
356+
return writeUnsignedVarInt<TUnsignedType>(buffer, offset, (static_cast<TUnsignedType>(value) << 1) ^ mask);
355357
}
356358

357359
static zend_object* byte_buffer_new(zend_class_entry* ce) {
@@ -656,17 +658,17 @@ PHP_RINIT_FUNCTION(encoding)
656658
ZEND_RAW_FENTRY(zend_name "LE", (zif_readType<native_type, (readFixedSizeType<native_type, ByteOrder::LittleEndian>), result_wrapper>), arg_info, ZEND_ACC_PUBLIC) \
657659
ZEND_RAW_FENTRY(zend_name "BE", (zif_readType<native_type, (readFixedSizeType<native_type, ByteOrder::BigEndian>), result_wrapper>), arg_info, ZEND_ACC_PUBLIC)
658660

659-
#define READ_VARINT_FENTRY(size, size_name, unsigned_type, signed_type) \
660-
ZEND_RAW_FENTRY("readUnsignedVar" size_name, (zif_readType<unsigned_type, (readUnsignedVarInt<size, unsigned_type>), zval_long_wrapper>), arginfo_read_integer, ZEND_ACC_PUBLIC) \
661-
ZEND_RAW_FENTRY("readSignedVar" size_name, (zif_readType<signed_type, (readSignedVarInt<size, unsigned_type, signed_type>), zval_long_wrapper>), arginfo_read_integer, ZEND_ACC_PUBLIC)
661+
#define READ_VARINT_FENTRY(size_name, unsigned_type, signed_type) \
662+
ZEND_RAW_FENTRY("readUnsignedVar" size_name, (zif_readType<unsigned_type, (readUnsignedVarInt<unsigned_type>), zval_long_wrapper>), arginfo_read_integer, ZEND_ACC_PUBLIC) \
663+
ZEND_RAW_FENTRY("readSignedVar" size_name, (zif_readType<signed_type, (readSignedVarInt<unsigned_type, signed_type>), zval_long_wrapper>), arginfo_read_integer, ZEND_ACC_PUBLIC)
662664

663665
#define WRITE_FIXED_TYPE_FENTRY(zend_name, native_type, parse_parameters_wrapper, arg_info) \
664666
ZEND_RAW_FENTRY(zend_name "LE", (zif_writeType<native_type, parse_parameters_wrapper<native_type>, (writeFixedSizeType<native_type, ByteOrder::LittleEndian>)>), arg_info, ZEND_ACC_PUBLIC) \
665667
ZEND_RAW_FENTRY(zend_name "BE", (zif_writeType<native_type, parse_parameters_wrapper<native_type>, (writeFixedSizeType<native_type, ByteOrder::BigEndian>)>), arg_info, ZEND_ACC_PUBLIC)
666668

667-
#define WRITE_VARINT_FENTRY(size, size_name, unsigned_type, signed_type) \
668-
ZEND_RAW_FENTRY("writeUnsignedVar" size_name, (zif_writeType<unsigned_type, zend_parse_parameters_long_wrapper<unsigned_type>, (writeUnsignedVarInt<size, unsigned_type>)>), arginfo_write_integer, ZEND_ACC_PUBLIC) \
669-
ZEND_RAW_FENTRY("writeSignedVar" size_name, (zif_writeType<signed_type, zend_parse_parameters_long_wrapper<signed_type>, (writeSignedVarInt<size, unsigned_type, signed_type>)>), arginfo_write_integer, ZEND_ACC_PUBLIC)
669+
#define WRITE_VARINT_FENTRY(size_name, unsigned_type, signed_type) \
670+
ZEND_RAW_FENTRY("writeUnsignedVar" size_name, (zif_writeType<unsigned_type, zend_parse_parameters_long_wrapper<unsigned_type>, (writeUnsignedVarInt<unsigned_type>)>), arginfo_write_integer, ZEND_ACC_PUBLIC) \
671+
ZEND_RAW_FENTRY("writeSignedVar" size_name, (zif_writeType<signed_type, zend_parse_parameters_long_wrapper<signed_type>, (writeSignedVarInt<unsigned_type, signed_type>)>), arginfo_write_integer, ZEND_ACC_PUBLIC)
670672

671673
static zend_function_entry byte_buffer_methods[] = {
672674
ZEND_RAW_FENTRY("readUnsignedByte", (zif_readType<uint8_t, readByte<uint8_t>, zval_long_wrapper>), arginfo_read_integer, ZEND_ACC_PUBLIC)
@@ -680,8 +682,8 @@ static zend_function_entry byte_buffer_methods[] = {
680682
READ_FIXED_TYPE_FENTRY("readFloat", float, zval_double_wrapper, arginfo_read_float)
681683
READ_FIXED_TYPE_FENTRY("readDouble", double, zval_double_wrapper, arginfo_read_float)
682684

683-
READ_VARINT_FENTRY(32, "Int", uint32_t, int32_t)
684-
READ_VARINT_FENTRY(64, "Long", uint64_t, int64_t)
685+
READ_VARINT_FENTRY("Int", uint32_t, int32_t)
686+
READ_VARINT_FENTRY("Long", uint64_t, int64_t)
685687

686688
ZEND_RAW_FENTRY("writeByte", (zif_writeType<int8_t, zend_parse_parameters_long_wrapper<int8_t>, writeByte>), arginfo_write_integer, ZEND_ACC_PUBLIC)
687689
WRITE_FIXED_TYPE_FENTRY("writeShort", int16_t, zend_parse_parameters_long_wrapper, arginfo_write_integer)
@@ -690,8 +692,8 @@ static zend_function_entry byte_buffer_methods[] = {
690692
WRITE_FIXED_TYPE_FENTRY("writeFloat", float, zend_parse_parameters_double_wrapper, arginfo_write_float)
691693
WRITE_FIXED_TYPE_FENTRY("writeDouble", double, zend_parse_parameters_double_wrapper, arginfo_write_float)
692694

693-
WRITE_VARINT_FENTRY(32, "Int", uint32_t, int32_t)
694-
WRITE_VARINT_FENTRY(64, "Long", uint64_t, int64_t)
695+
WRITE_VARINT_FENTRY("Int", uint32_t, int32_t)
696+
WRITE_VARINT_FENTRY("Long", uint64_t, int64_t)
695697

696698
PHP_ME(ByteBuffer, __construct, ByteBuffer___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
697699
PHP_ME(ByteBuffer, toString, ByteBuffer_toString, ZEND_ACC_PUBLIC)

0 commit comments

Comments
 (0)