-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
src: reduced substring calls #34808
src: reduced substring calls #34808
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@jasnell @joyeecheung There have been some small changes since your reviews. Can you re-review? |
src/node_file.cc
Outdated
ret.substr(ret.size() - extension.size()) == extension) { | ||
ret = ret.substr(0, ret.size() - extension.size()); | ||
if (str_size >= extension.size() && | ||
// Because we still have the whole string intact |
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 don't really understand this comment. Is it supposed to mean "This is possible because we still have the whole string intact"? If so, it only makes sense in the context of this change. I don't think it explains the code well.
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 intention of the comment is around the choice of using the start index for comparison. Maybe it can be written in a better way. I will work on it.
src/node_file.cc
Outdated
ret = ret.substr(0, ret.size() - extension.size()); | ||
if (str_size >= extension.size() && | ||
// Because we still have the whole string intact | ||
str.substr(start_pos + str_size - extension.size()) == 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.
If the goal is to remove str.substr
(presumably because it allocated memory), why not replace this with str.compare
? Or does the compiler optimize this substr
call away?
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 sure about the implementation of compare and how it handles the comparison and allocation but from a higher level point of view it seems valid.
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.
compare
returns an integer. If the strings are equal, the return value is 0
.
b3954ad
to
34d7ff5
Compare
Reduced the number of substring calls by 1 as it is a linear time complexity function. Thus having a larger path might lead to decrease in performance. Also removed unnecessary string allocation happening in the block.
34d7ff5
to
ec75ce2
Compare
This comment has been minimized.
This comment has been minimized.
Landed in 4cfa5df...2e4930b |
Reduced the number of substring calls by 1 as it is a linear time complexity function. Thus having a larger path might lead to decrease in performance. Also removed unnecessary string allocation happening in the block. PR-URL: #34808 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Reduced the number of substring calls by 1 as it is a linear time complexity function. Thus having a larger path might lead to decrease in performance. Also removed unnecessary string allocation happening in the block. PR-URL: #34808 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Reduced the number of substring calls by 1 as it is a linear time complexity function. Thus having a larger path might lead to decrease in performance. Also removed unnecessary string allocation happening in the block. PR-URL: nodejs#34808 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes