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

Conversation

yashLadha
Copy link
Contributor

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++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. labels Aug 17, 2020
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 21, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 21, 2020
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@Trott
Copy link
Member

Trott commented Aug 23, 2020

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

@nodejs-github-bot
Copy link
Collaborator

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

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
Contributor Author

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

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
Contributor Author

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

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 September 6, 2020 04:39
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 Add this label to start a Jenkins CI on a PR. label Sep 6, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 6, 2020
@nodejs-github-bot

This comment has been minimized.

@tniessen tniessen added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 6, 2020
@aduh95 aduh95 added commit-queue Add this label to land a pull request using GitHub Actions. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 11, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 11, 2020
@nodejs-github-bot
Copy link
Collaborator

@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 11, 2020
@github-actions
Copy link
Contributor

Landed in 4cfa5df...2e4930b

@github-actions github-actions bot closed this Oct 11, 2020
nodejs-github-bot pushed a commit that referenced this pull request 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 October 12, 2020 00:36
MylesBorins pushed a commit that referenced this pull request 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 pushed a commit to joesepi/node that referenced this pull request 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 PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants