Skip to content

Commit 0c57118

Browse files
committed
Add zend_ulong_to_str() API
No point in going through a smart_str and append_unsigned if we can construct the result directly...
1 parent 65a5c18 commit 0c57118

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Zend/zend_operators.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,17 @@ ZEND_API zend_string* ZEND_FASTCALL zend_long_to_str(zend_long num) /* {{{ */
30443044
}
30453045
/* }}} */
30463046

3047+
ZEND_API zend_string* ZEND_FASTCALL zend_ulong_to_str(zend_ulong num)
3048+
{
3049+
if (num <= 9) {
3050+
return ZSTR_CHAR((zend_uchar)'0' + (zend_uchar)num);
3051+
} else {
3052+
char buf[MAX_LENGTH_OF_LONG + 1];
3053+
char *res = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num);
3054+
return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3055+
}
3056+
}
3057+
30473058
/* buf points to the END of the buffer */
30483059
static zend_always_inline char *zend_print_u64_to_buf(char *buf, uint64_t num64) {
30493060
#if SIZEOF_ZEND_LONG == 8

Zend/zend_operators.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ static zend_always_inline char *zend_print_long_to_buf(char *buf, zend_long num)
876876
}
877877

878878
ZEND_API zend_string* ZEND_FASTCALL zend_long_to_str(zend_long num);
879+
ZEND_API zend_string* ZEND_FASTCALL zend_ulong_to_str(zend_ulong num);
879880
ZEND_API zend_string* ZEND_FASTCALL zend_u64_to_str(uint64_t num);
880881
ZEND_API zend_string* ZEND_FASTCALL zend_i64_to_str(int64_t num);
881882

ext/pgsql/pgsql.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@
6464
#if ZEND_LONG_MAX < UINT_MAX
6565
#define PGSQL_RETURN_OID(oid) do { \
6666
if (oid > ZEND_LONG_MAX) { \
67-
smart_str s = {0}; \
68-
smart_str_append_unsigned(&s, oid); \
69-
smart_str_0(&s); \
70-
RETURN_NEW_STR(s.s); \
67+
RETURN_STR(zend_ulong_to_str(oid)); \
7168
} \
7269
RETURN_LONG((zend_long)oid); \
7370
} while(0)

0 commit comments

Comments
 (0)