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
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

return ((size + 2 - ((size + 2) % 3)) / 3 * 4);
}

// Doesn't check for padding at the end. Can be 1-2 bytes over.
static inline size_t base64_decoded_size_fast(size_t size) {
Expand Down Expand Up @@ -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.

return unbase64_table[x];
}


template <typename TypeName>
Expand Down
1 change: 1 addition & 0 deletions src/inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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?

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.

static void generate_accept_string(const std::string& client_key,
char (*buffer)[ACCEPT_KEY_LENGTH]) {
// Magic string from websockets spec.
Expand Down