-
Notifications
You must be signed in to change notification settings - Fork 683
Optimize string character access for ascii strings #971
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
Optimize string character access for ascii strings #971
Conversation
return ecma_number_to_utf8_string (*num_p, buffer, sizeof (buffer)); | ||
} /* ecma_string_get_heap_number_size */ | ||
|
||
#define ECMA_STRING_IS_ASCII(char_p, size) ((size) == lit_utf8_string_length ((char_p), (size))) |
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.
Missing comment
|
bool is_ascii; | ||
const lit_utf8_byte_t *chars_p = ecma_string_raw_chars (string_p, &buffer_size, &is_ascii); | ||
|
||
if (chars_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.
I can't see how could be the chars_p NULL. Could you show me an example? :)
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 found out. (ECMA_STRING_CONTAINER_UINT32_IN_DESC and ECMA_STRING_CONTAINER_HEAP_NUMBER has no raw string data)
6cf4065
to
a5143e1
Compare
Please review the patch again. |
* The ecma string ref and container fields should fill the 16 bit field. | ||
*/ | ||
JERRY_STATIC_ASSERT ((ECMA_STRING_MAX_REF | ECMA_STRING_CONTAINER_MASK) == UINT16_MAX, | ||
ecma_string_ref_and_container_fields_should_fill_the_16_bit_field); |
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 think one more static assert is missing: the one that checks that ECMA_STRING_CONTAINER_MASK
is bigger than or equal to the largest possible value of ecma_string_container_t
.
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.
Shall I add a new enum for max testing? I wouldn't want to overdo this.
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.
A new enum is certainly not needed. But you can add a new label to the end of the existing ecma_string_container_t
to get the count of labels automatically calculated. I've seen that used in some other enums as well (and called something like xxx__COUNT
).
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.
Unfortunately the side effect is that I need to extend switches with this new value (doesn't look too nice). Do you still want it?
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 still would like to see an assert and also an automatically calculated __COUNT label for the enum. But that does not necessarily require the extension of switches.
I've looked for the switches with ECMA_STRING_CONTAINER_
case labels and almost all of them already had default branches with some kind of an assert (unreachable, or checking for an explicitly given container type), which is what they should do IMHO. The only exception I've found is in function ecma_deref_ecma_string
, which does not check for invalid values -- but it should (or already should have) IMHO!
Where have you found switches that needed extension?
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.
Added a commit which adds the changes.
I don't really like the double JERRY_UNREACHABLE() sequences.
68d7253
to
218d8c2
Compare
Patch updated with a new approach. |
LGTM, but please update the copyright headers in
|
@zherczeg With the latest revision, you loose an important feature of the Regarding the |
"someone forgot to update the code that works with it" -> this is my biggest fear. Updating a max is easy, since it is around the typedef, and whoever works with it will notice it. However, default branches eliminate compiler warnings and will create hidden errors which the testing system might not capture (or a lot of debugging needed). Personally I like full (all values checked) switches without defaults. Anyway if you insist I will do your request even if I don't agree at all. |
218d8c2
to
5911f72
Compare
I changed the __MAX to be part of the enum, and it works. |
LGTM (FWIW) |
…store to allow two byte hashes in the future. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
5911f72
to
af24694
Compare
Copyright updated. |
Optimize string character access for ascii strings and refactor type store to allow two byte hashes in the future.