-
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_CHAR(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 { \ | ||
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_CHAR(c) ZVAL_CHAR(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_CHAR(c) do { RETVAL_CHAR(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))) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@kocsismate
sorry for my poor English...😢
you can add comments if possible...