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: change macro to fn #23603

Closed
wants to merge 2 commits into from

Conversation

ginonott
Copy link

@ginonott ginonott commented Oct 12, 2018

Change base64_encoded_size and unbase64 to inline functions. The base64_encoded_size
is a constexpr to be used in function declarations.

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

Change base64_encoded_size and unbase64 to inline functions. The base64_encoded_size
is a constexpr to be used in function declarations.
@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol labels Oct 12, 2018
Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Any reason for marking this WIP? It looks good to me :)

@@ -143,6 +143,7 @@ enum ws_decode_result {
FRAME_OK, FRAME_INCOMPLETE, FRAME_CLOSE, FRAME_ERROR
};


Copy link
Member

Choose a reason for hiding this comment

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

I think this is an unrelated whitespace change?

@jasnell jasnell added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Oct 12, 2018
@ginonott ginonott changed the title [WIP] change macro to fn Change macro to fn Oct 12, 2018
@refack
Copy link
Contributor

refack commented Oct 12, 2018

Hello @ginonott and thank you for your contribution 🥇
I left a few comments, but generally I like the approach of this PR.

BTW: So that this submission could be attributed to you properly, you might want to make sure your GitHub email, and local git email are set up to your liking (Ref: https://help.github.com/articles/setting-your-commit-email-address-on-github/)

@refack refack removed the inspector Issues and PRs related to the V8 inspector protocol label Oct 12, 2018
@@ -10,8 +10,9 @@

namespace node {
//// Base 64 ////
#define base64_encoded_size(size) ((size + 2 - ((size + 2) % 3)) / 3 * 4)

static inline constexpr size_t base64_encoded_size(size_t size) {
Copy link
Contributor

Choose a reason for hiding this comment

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

constexpr implies inline, so no need to specify inline

Copy link
Contributor

Choose a reason for hiding this comment

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

https://en.cppreference.com/w/cpp/language/constexpr says

A constexpr specifier used in a function or static member variable (since C++17) declaration implies inline

We are not yet at C++17, right? IINW, We are still at C++14.

Copy link
Contributor

Choose a reason for hiding this comment

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

CPPReference is tricky to read. It's only the static member variable (since C++17) part that is the addition to C++17 (see this change)
In C++11 there were no constexpr static member variables, they were added in C++17.

@@ -143,6 +143,7 @@ enum ws_decode_result {
FRAME_OK, FRAME_INCOMPLETE, FRAME_CLOSE, FRAME_ERROR
};


Copy link
Contributor

Choose a reason for hiding this comment

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

Unneeded whitespace change.

@@ -48,8 +49,9 @@ size_t base64_decoded_size(const TypeName* src, size_t size) {
extern const int8_t unbase64_table[256];


#define unbase64(x) \
static_cast<uint8_t>(unbase64_table[static_cast<uint8_t>(x)])
inline static int8_t unbase64(uint8_t x) {
Copy link
Contributor

@refack refack Oct 12, 2018

Choose a reason for hiding this comment

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

IIUC if you declare unbase64_table as constexpr you could declare this function as constexpr as well.

@BridgeAR BridgeAR changed the title Change macro to fn src: change macro to fn Oct 12, 2018
@addaleax
Copy link
Member

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 15, 2018
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Oct 15, 2018
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: nodejs#23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Oct 15, 2018
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: nodejs#23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@BridgeAR
Copy link
Member

Landed in 17c35a6 🎉

@ginonott congratulations on your first commit to Node.js!

@BridgeAR BridgeAR closed this Oct 15, 2018
jasnell pushed a commit that referenced this pull request Oct 17, 2018
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: #23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
addaleax pushed a commit that referenced this pull request Oct 20, 2018
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: #23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 30, 2018
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: #23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@codebytere codebytere mentioned this pull request Nov 27, 2018
rvagg pushed a commit that referenced this pull request Nov 28, 2018
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: #23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
MylesBorins pushed a commit that referenced this pull request Nov 29, 2018
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: #23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@codebytere codebytere mentioned this pull request Nov 29, 2018
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. buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants