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

src: prefer C++ empty() in boolean expressions by tniessen · Pull Request #34432 · nodejs/node · GitHub

/ node Public

src: prefer C++ empty() in boolean expressions - #34432

Closed
tniessen wants to merge 1 commit into
nodejs:masterfrom
tniessen:src-prefer-cpp-empty
Closed

src: prefer C++ empty() in boolean expressions#34432
tniessen wants to merge 1 commit into
nodejs:masterfrom
tniessen:src-prefer-cpp-empty

Conversation

Copy link
Copy Markdown
Member

This changes occurrences of length() and size() to empty() where it makes the code simpler.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

tniessen added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jul 19, 2020
tniessen requested a review from a team July 19, 2020 21:29
nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jul 19, 2020

Copy link
Copy Markdown
Member

Maybe also add readability-container-size-empty to https://github.com/nodejs/node/blob/a42dcbeb43ab22c0db07c4e0a9eab5e0f44578f4/src/.clang-tidy.

Comment thread src/node_url.cc Outdated
Comment on lines 2039 to 2042

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

Wildly inefficient way of removing empty prefixes... (n reallocations + n*m copies when 1 + m suffices)

Suggested change
while (url->path.size() > 1 && url->path[0].empty()) {
url->path.erase(url->path.begin());
}
auto begin = url->path.begin();
auto end = url->path.end();
auto from = begin;
auto to = begin;
while (to != end && to->empty()) ++to;
if (to == end && from == begin && from != to) ++from;
url->path.erase(from, to); // 1 + m

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

@bnoordhuis In your suggestion, the from == begin part is always true, unless i’m missing something?

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

Sorry, yeah. It was intended as a kind of self-documentation about the preconditions but I guess it's confusing more than anything else. if (to == end && from != end) ++from; is probably a clearer way of writing it.

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

As this is not directly related to the other changes in this PR, this could be done in a separate commit/PR.

devsnek 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

the future is now

gengjiawen commented Jul 20, 2020
edited
Loading

Copy link
Copy Markdown
Member

Failed test case in macOS. is this a flaky test ? cc @Trott

Path: parallel/test-macos-app-sandbox
--- stderr ---
assert.js:103
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

1 !== 0

    at Object.<anonymous> (/Users/runner/work/node/node/test/parallel/test-macos-app-sandbox.js:41:8)
    at Module._compile (internal/modules/cjs/loader.js:1252:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1273:10)
    at Module.load (internal/modules/cjs/loader.js:1101:32)
    at Function.Module._load (internal/modules/cjs/loader.js:966:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: 1,
  expected: 0,
  operator: 'strictEqual'
}

Comment thread src/quic/node_quic_crypto.cc Outdated
tniessen force-pushed the src-prefer-cpp-empty branch from 36b41e6 to 11d860c Compare August 9, 2020 16:47
gengjiawen added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 10, 2020
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 10, 2020

Copy link
Copy Markdown
Collaborator

tniessen added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Aug 10, 2020
tniessen requested review from a team as code owners August 10, 2020 16:06

jasnell commented Aug 11, 2020

Copy link
Copy Markdown
Member

Landed in 1be7bbd

jasnell closed this Aug 11, 2020
jasnell pushed a commit that referenced this pull request Aug 11, 2020
PR-URL: #34432
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Aug 17, 2020
PR-URL: #34432
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
danielleadams mentioned this pull request Aug 20, 2020
BethGriggs pushed a commit that referenced this pull request Aug 20, 2020
PR-URL: #34432
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
addaleax pushed a commit that referenced this pull request Sep 22, 2020
PR-URL: #34432
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
addaleax pushed a commit that referenced this pull request Sep 22, 2020
PR-URL: #34432
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
codebytere mentioned this pull request Sep 28, 2020
tniessen removed the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Jan 14, 2021
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

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL