Skip to content

Commit db64c1c

Browse files
committed
zend introduce const GNUC attribute. sub optimisation where there is no pointers, nor particular memory layout, thread local/volatile ... involved. usage concealed for now into little pack helpers.
Closes php#9326.
1 parent ac9cbb7 commit db64c1c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Zend/zend_portability.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ char *alloca();
228228
# define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y)
229229
#endif
230230

231+
#if ZEND_GCC_VERSION >= 3000
232+
# define ZEND_ATTRIBUTE_CONST __attribute__((const))
233+
#else
234+
# define ZEND_ATTRIBUTE_CONST
235+
#endif
236+
231237
#if ZEND_GCC_VERSION >= 2007 || __has_attribute(format)
232238
# define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
233239
#else

ext/standard/pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ static void php_pack(zval *val, size_t size, int *map, char *output)
102102
}
103103
/* }}} */
104104

105-
static inline uint16_t php_pack_reverse_int16(uint16_t arg)
105+
ZEND_ATTRIBUTE_CONST static inline uint16_t php_pack_reverse_int16(uint16_t arg)
106106
{
107107
return ((arg & 0xFF) << 8) | ((arg >> 8) & 0xFF);
108108
}
109109

110110
/* {{{ php_pack_reverse_int32 */
111-
static inline uint32_t php_pack_reverse_int32(uint32_t arg)
111+
ZEND_ATTRIBUTE_CONST static inline uint32_t php_pack_reverse_int32(uint32_t arg)
112112
{
113113
uint32_t result;
114114
result = ((arg & 0xFF) << 24) | ((arg & 0xFF00) << 8) | ((arg >> 8) & 0xFF00) | ((arg >> 24) & 0xFF);

0 commit comments

Comments
 (0)