-
Notifications
You must be signed in to change notification settings - Fork 10
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
parser: improve string parsing #66
Conversation
belochub
commented
Feb 10, 2017
- Eliminate unnecessary assignments.
- Encode control characters in place to avoid copying and memory allocations.
src/jsrs_parser.cc
Outdated
const char* str, | ||
size_t* res_len, | ||
size_t* size, | ||
char* write_to); |
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.
Please align the parameter to match the surrounding style.
char* symb = | ||
GetControlChar(isolate, begin + ++i, &out_offset, &in_offset); | ||
if (!symb) { | ||
bool ok = GetControlChar(isolate, begin + ++i, &out_offset, &in_offset, |
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.
So that doesn't need copying at all, even to a stack-allocated buffer. Good catch!
if (!symb) { | ||
bool ok = GetControlChar(isolate, begin + ++i, &out_offset, &in_offset, | ||
result + res_index); | ||
if (!ok) { |
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 do you think about making it one-line?
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, that way it is more understandable than just
if (!GetControlChar(...)) {
Compiler should optimize it anyway.
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.
Never mind, for some reason it seemed to me that there's one short statement inside the if
body, so I proposed to eliminate braces.
src/jsrs_parser.cc
Outdated
const char* str, | ||
size_t* res_len, | ||
size_t* size, | ||
char* write_to) { |
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.
The same alignment issue as above.
dfb1fd8
to
2bd9174
Compare
break; | ||
} | ||
case 'v': { | ||
*result = '\v'; | ||
*write_to = '\v'; | ||
break; | ||
} | ||
case '0': { |
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.
(Not related to this PR)
Do we really need '\0'
as a special case here? Either we support any octal sequences, or we don't support them at all.
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.
Yeah, I guess we don'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.
Will make a new PR for this.
Added fix for possible memory leak in string parsing. |
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak.
2bd9174
to
362e73c
Compare
@aqrln updated with alignment fixes. |
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.
LGTM
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
Landed in 779965d. |
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: #66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: metarhia/jstp#66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: metarhia/jstp#66
* Eliminate unnecessary assignments. * Encode control characters in place to avoid copying and memory allocations. * Fix possible memory leak. PR-URL: metarhia/jstp#66