Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

yashLadha
Copy link
Member

@yashLadha yashLadha commented Aug 17, 2020

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ fs labels Aug 17, 2020
@joyeecheung joyeecheung added the request-ci label Aug 21, 2020
@github-actions github-actions bot removed the request-ci label Aug 21, 2020
@nodejs-github-bot

This comment has been hidden.

@nodejs-github-bot

This comment has been hidden.

@Trott
Copy link
Member

@Trott Trott commented Aug 23, 2020

@jasnell @joyeecheung There have been some small changes since your reviews. Can you re-review?

@Trott Trott requested review from jasnell and joyeecheung Aug 23, 2020
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Aug 23, 2020

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
Copy link
Member

@tniessen tniessen Sep 5, 2020

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.

Copy link
Member Author

@yashLadha yashLadha Sep 5, 2020

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) {
Copy link
Member

@tniessen tniessen Sep 5, 2020

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?

Copy link
Member Author

@yashLadha yashLadha Sep 5, 2020

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.

Copy link
Member

@tniessen tniessen Sep 5, 2020

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.

@yashLadha yashLadha force-pushed the faster_basename branch 3 times, most recently from b3954ad to 34d7ff5 Compare Sep 6, 2020
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.
@tniessen tniessen added the request-ci label Sep 6, 2020
@github-actions github-actions bot removed the request-ci label Sep 6, 2020
@nodejs-github-bot

This comment has been hidden.

@tniessen tniessen added the author ready label Sep 6, 2020
aduh95
aduh95 approved these changes Oct 11, 2020
@aduh95 aduh95 added commit-queue request-ci labels Oct 11, 2020
@github-actions github-actions bot removed the request-ci label Oct 11, 2020
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Oct 11, 2020

@github-actions github-actions bot removed the commit-queue label Oct 11, 2020
@github-actions
Copy link

@github-actions github-actions bot commented Oct 11, 2020

Landed in 4cfa5df...2e4930b

@github-actions github-actions bot closed this Oct 11, 2020
nodejs-github-bot added a commit that referenced this issue Oct 11, 2020
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 <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@yashLadha yashLadha deleted the faster_basename branch Oct 12, 2020
MylesBorins added a commit that referenced this issue Oct 14, 2020
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 <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Oct 14, 2020
joesepi added a commit to joesepi/node that referenced this issue Jan 8, 2021
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 <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready c++ fs
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants