-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add zend_string_init_fast and related macros to speed up string creation #5684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -636,6 +636,20 @@ END_EXTERN_C() | |
ZVAL_PSTRINGL(z, "", 0); \ | ||
} while (0) | ||
|
||
#define ZVAL_ONE_CHAR_STRING(z, c) do { \ | ||
char _c = (c); \ | ||
ZVAL_INTERNED_STR(z, ZSTR_CHAR((zend_uchar) _c)); \ | ||
} while (0) | ||
|
||
#define ZVAL_STRINGL_FAST(z, s, l) do { \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a comment to clarify when the fast implementation should be used? I believe there are some people (including me) who would appreciate a little bit more information about its applicability/use-cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kocsismate |
||
ZVAL_STR(z, zend_string_init_fast(s, l)); \ | ||
} while (0) | ||
|
||
#define ZVAL_STRING_FAST(z, s) do { \ | ||
const char *_s = (s); \ | ||
ZVAL_STRINGL_FAST(z, _s, strlen(_s)); \ | ||
} while (0) | ||
|
||
#define ZVAL_ZVAL(z, zv, copy, dtor) do { \ | ||
zval *__z = (z); \ | ||
zval *__zv = (zv); \ | ||
|
@@ -654,46 +668,52 @@ END_EXTERN_C() | |
} while (0) | ||
|
||
#define RETVAL_BOOL(b) ZVAL_BOOL(return_value, b) | ||
#define RETVAL_NULL() ZVAL_NULL(return_value) | ||
#define RETVAL_LONG(l) ZVAL_LONG(return_value, l) | ||
#define RETVAL_DOUBLE(d) ZVAL_DOUBLE(return_value, d) | ||
#define RETVAL_STR(s) ZVAL_STR(return_value, s) | ||
#define RETVAL_INTERNED_STR(s) ZVAL_INTERNED_STR(return_value, s) | ||
#define RETVAL_NEW_STR(s) ZVAL_NEW_STR(return_value, s) | ||
#define RETVAL_STR_COPY(s) ZVAL_STR_COPY(return_value, s) | ||
#define RETVAL_STRING(s) ZVAL_STRING(return_value, s) | ||
#define RETVAL_STRINGL(s, l) ZVAL_STRINGL(return_value, s, l) | ||
#define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value) | ||
#define RETVAL_RES(r) ZVAL_RES(return_value, r) | ||
#define RETVAL_ARR(r) ZVAL_ARR(return_value, r) | ||
#define RETVAL_NULL() ZVAL_NULL(return_value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously I also tried to do something similar, but it turned out that tabs should only be used for indentation at the beginning of the line. Otherwise, spaces are preferred. |
||
#define RETVAL_LONG(l) ZVAL_LONG(return_value, l) | ||
#define RETVAL_DOUBLE(d) ZVAL_DOUBLE(return_value, d) | ||
#define RETVAL_STR(s) ZVAL_STR(return_value, s) | ||
#define RETVAL_INTERNED_STR(s) ZVAL_INTERNED_STR(return_value, s) | ||
#define RETVAL_NEW_STR(s) ZVAL_NEW_STR(return_value, s) | ||
#define RETVAL_STR_COPY(s) ZVAL_STR_COPY(return_value, s) | ||
#define RETVAL_STRING(s) ZVAL_STRING(return_value, s) | ||
#define RETVAL_STRINGL(s, l) ZVAL_STRINGL(return_value, s, l) | ||
#define RETVAL_STRING_FAST(s) ZVAL_STRING_FAST(return_value, s) | ||
#define RETVAL_STRINGL_FAST(s, l) ZVAL_STRINGL_FAST(return_value, s, l) | ||
#define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value) | ||
#define RETVAL_ONE_CHAR_STRING(c) ZVAL_ONE_CHAR_STRING(return_value, c) | ||
#define RETVAL_RES(r) ZVAL_RES(return_value, r) | ||
#define RETVAL_ARR(r) ZVAL_ARR(return_value, r) | ||
#define RETVAL_EMPTY_ARRAY() ZVAL_EMPTY_ARRAY(return_value) | ||
#define RETVAL_OBJ(r) ZVAL_OBJ(return_value, r) | ||
#define RETVAL_OBJ(r) ZVAL_OBJ(return_value, r) | ||
#define RETVAL_COPY(zv) ZVAL_COPY(return_value, zv) | ||
#define RETVAL_COPY_VALUE(zv) ZVAL_COPY_VALUE(return_value, zv) | ||
#define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor) | ||
#define RETVAL_FALSE ZVAL_FALSE(return_value) | ||
#define RETVAL_TRUE ZVAL_TRUE(return_value) | ||
#define RETVAL_FALSE ZVAL_FALSE(return_value) | ||
#define RETVAL_TRUE ZVAL_TRUE(return_value) | ||
|
||
#define RETURN_BOOL(b) do { RETVAL_BOOL(b); return; } while (0) | ||
#define RETURN_NULL() do { RETVAL_NULL(); return;} while (0) | ||
#define RETURN_LONG(l) do { RETVAL_LONG(l); return; } while (0) | ||
#define RETURN_DOUBLE(d) do { RETVAL_DOUBLE(d); return; } while (0) | ||
#define RETURN_BOOL(b) do { RETVAL_BOOL(b); return; } while (0) | ||
#define RETURN_NULL() do { RETVAL_NULL(); return;} while (0) | ||
#define RETURN_LONG(l) do { RETVAL_LONG(l); return; } while (0) | ||
#define RETURN_DOUBLE(d) do { RETVAL_DOUBLE(d); return; } while (0) | ||
#define RETURN_STR(s) do { RETVAL_STR(s); return; } while (0) | ||
#define RETURN_INTERNED_STR(s) do { RETVAL_INTERNED_STR(s); return; } while (0) | ||
#define RETURN_NEW_STR(s) do { RETVAL_NEW_STR(s); return; } while (0) | ||
#define RETURN_STR_COPY(s) do { RETVAL_STR_COPY(s); return; } while (0) | ||
#define RETURN_STRING(s) do { RETVAL_STRING(s); return; } while (0) | ||
#define RETURN_STRINGL(s, l) do { RETVAL_STRINGL(s, l); return; } while (0) | ||
#define RETURN_STRING_FAST(s) do { RETVAL_STRING_FAST(s); return; } while (0) | ||
#define RETURN_STRINGL_FAST(s, l) do { RETVAL_STRINGL_FAST(s, l); return; } while (0) | ||
#define RETURN_EMPTY_STRING() do { RETVAL_EMPTY_STRING(); return; } while (0) | ||
#define RETURN_RES(r) do { RETVAL_RES(r); return; } while (0) | ||
#define RETURN_ARR(r) do { RETVAL_ARR(r); return; } while (0) | ||
#define RETURN_ONE_CHAR_STRING(c) do { RETVAL_ONE_CHAR_STRING(c); return; } while (0) | ||
#define RETURN_RES(r) do { RETVAL_RES(r); return; } while (0) | ||
#define RETURN_ARR(r) do { RETVAL_ARR(r); return; } while (0) | ||
#define RETURN_EMPTY_ARRAY() do { RETVAL_EMPTY_ARRAY(); return; } while (0) | ||
#define RETURN_OBJ(r) do { RETVAL_OBJ(r); return; } while (0) | ||
#define RETURN_OBJ(r) do { RETVAL_OBJ(r); return; } while (0) | ||
#define RETURN_COPY(zv) do { RETVAL_COPY(zv); return; } while (0) | ||
#define RETURN_COPY_VALUE(zv) do { RETVAL_COPY_VALUE(zv); return; } while (0) | ||
#define RETURN_ZVAL(zv, copy, dtor) do { RETVAL_ZVAL(zv, copy, dtor); return; } while (0) | ||
#define RETURN_FALSE do { RETVAL_FALSE; return; } while (0) | ||
#define RETURN_TRUE do { RETVAL_TRUE; return; } while (0) | ||
#define RETURN_FALSE do { RETVAL_FALSE; return; } while (0) | ||
#define RETURN_TRUE do { RETVAL_TRUE; return; } while (0) | ||
#define RETURN_THROWS() do { ZEND_ASSERT(EG(exception)); (void) return_value; return; } while (0) | ||
|
||
#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties(Z_OBJ_P(p)) : NULL))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about using
ZVAL_ONE_CHAR_INTERNED_STR
? So that we wouldn't lose the information that it creates an interned string?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but API named
*_STR
usually takeszend_string *
as a parameter andZVAL_ONE_CHAR_INTERNED_STRING
is too long...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length of a macro name is not a valid argument IMHO, readability is more important than just how many characters less you will type once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I prefer
ZVAL_ONE_CHAR_INTERNED_STRING
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twose Using
str
vsstring
has a semantic difference. Please see this here: #5647 (comment) Initially, I also argued against using abbreviations, but "unfortunately" they make sense in this case. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kocsismate I'm a little confused now, this macro accepts a parameter of type
char
, notzend_string *
, so we named it*_ONE_CHAR_INTERNED_STRING
instead ofONE_CHAR_INTERNED_STR
, is that right?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using just
ZVAL_CHAR(zv, c)
,RETVAL_CHAR(c)
,RETURN_CHAR(c)
... :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of your proposal, the reason I didn’t do this at first was that there is no
char
type in PHP