FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

src: prefer data accessor of string and vector by VoltrexKeyva · Pull Request #47750 · nodejs/node · GitHub

/ node Public

src: prefer data accessor of string and vector - #47750

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
VoltrexKeyva:prefer-data-acc
May 3, 2023
Merged

src: prefer data accessor of string and vector#47750
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
VoltrexKeyva:prefer-data-acc

Conversation

VoltrexKeyva commented Apr 27, 2023
edited
Loading

Copy link
Copy Markdown
Contributor

The pattern of getting the address of the element at index 0 of a container is generally used to materialize a pointer to the backing data of a container, however std::string and std::vector provide a data() accessor to retrieve the data pointer which should be preferred.

This also ensures that in the case that the container is empty, the data pointer access does not perform an errant memory access.

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net
  • @nodejs/startup

nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 27, 2023

Copy link
Copy Markdown
Contributor Author

Seems like a recent change unsatisfied the JavaScript coverage threshold.

daeyeon added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no outstanding review comments, and a CI started. labels Apr 28, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 28, 2023

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

The pattern of getting the address of the element at index 0 of a
container is generally used to materialize a pointer to the backing
data of a container, however `std::string` and `std::vector`
provide a `data()` accessor to retrieve the data pointer which
should be preferred.

This also ensures that in the case that the container is empty, the
data pointer access does not perform an errant memory access.

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

VoltrexKeyva added the request-ci Add this label to start a Jenkins CI on a PR. label May 3, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 3, 2023

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

VoltrexKeyva added the commit-queue Add this label to land a pull request using GitHub Actions. label May 3, 2023
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 3, 2023
nodejs-github-bot merged commit dd6eb67 into nodejs:main May 3, 2023

Copy link
Copy Markdown
Collaborator

Landed in dd6eb67

VoltrexKeyva deleted the prefer-data-acc branch May 3, 2023 14:21
targos pushed a commit that referenced this pull request May 12, 2023
The pattern of getting the address of the element at index 0 of a
container is generally used to materialize a pointer to the backing
data of a container, however `std::string` and `std::vector`
provide a `data()` accessor to retrieve the data pointer which
should be preferred.

This also ensures that in the case that the container is empty, the
data pointer access does not perform an errant memory access.

PR-URL: #47750
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
danielleadams pushed a commit that referenced this pull request Jul 6, 2023
The pattern of getting the address of the element at index 0 of a
container is generally used to materialize a pointer to the backing
data of a container, however `std::string` and `std::vector`
provide a `data()` accessor to retrieve the data pointer which
should be preferred.

This also ensures that in the case that the container is empty, the
data pointer access does not perform an errant memory access.

PR-URL: #47750
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
MoLow pushed a commit to MoLow/node that referenced this pull request Jul 6, 2023
The pattern of getting the address of the element at index 0 of a
container is generally used to materialize a pointer to the backing
data of a container, however `std::string` and `std::vector`
provide a `data()` accessor to retrieve the data pointer which
should be preferred.

This also ensures that in the case that the container is empty, the
data pointer access does not perform an errant memory access.

PR-URL: nodejs#47750
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 outstanding review comments, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL