-
Notifications
You must be signed in to change notification settings - Fork 440
String handling improvements #331
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
String handling improvements #331
Conversation
Also depends on #332 |
@akiss77, please rebase and squash |
* iotjs::ReadFile: Read file contents in one go instead of doing it in a loop. * iotjs::JObject: Remove String-based method variants. Those variants are completely unused in the project. All Error constructions and property accesses are char*-based. (Should they be needed in the future, then a better implementation is suggested: the now-removed String-based methods always fell back to the char*-based variant by simply passing on the memory buffer of the String. However, they could have their own clone of the function body invoking _sz jerry API variants and passing the size of the String, so that length re-computation does not happen.) * iotjs::JObject::JObject(const String&): The jerry API has a create_string_sz variant that takes size as a second parameter, if already known. Since every String knows its own size, we can make use of it. This also implies that we don't need to assert that the String has memory allocated, since create_string_sz can deal with NULL if size is 0. * iotjs::JObject::GetString(): When a String is contructed just to be filled in later, there is no need to be constructed with the empty "" string; NULL is enough as source data, memory will be allocated anyway for the specified size. * iotjs::String copy constructor: Add clarification comment. * iotjs_module_buffer.cpp/___ToString_native(): Create String right away with buffer data. Make sure String capacity is at least one, so that String allocates memory. * iotjs_module_buffer.cpp/___ToString_native(): Precompute length of string in the buffer (look for the terminating zero) and create String with that size. This may even improve memory and performance slightly by not allocating and copying unneeded parts for/of the buffer. * iotjs_module_process.cpp/___CompileNativePtr_native(): The loop scanning through the natives array superfluously replicates the functionality of the standard strcmp. * iotjs_module_httpparser.cpp: JObject can be directly constructed from String, there is no need for taking its raw pointer. * calls to Eval: Prevent re-calculation of string lengths when already known. IoT.js-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
28eeb0e
to
16de549
Compare
@LaszloLango done |
@@ -51,6 +51,9 @@ class String { | |||
explicit String(const char* data, int size = -1, int cap = -1); | |||
|
|||
// Create string object from other string object. | |||
// (Actually unimplemented. Declaration of copy constructor is needed for | |||
// return value optimization to work. However, linker error will be emitted | |||
// if copy construction is used in any other situation.) | |||
String(const String& other); |
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.
IMHO this should be private if it is only for RVO.
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 have to fix myself. That would break RVO.
@akiss77, thanks. LGTM |
LGTM |
remove the CONFIG_CANCELLATION_POINTS conditional at task_setcancelty…
I've reviewed some of the string handling parts of the code base. This PR show the results of my findings spearated into independent patches.
Builds on #330