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: turn ROUND_UP into an inline function #25743

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Headers::Headers(Isolate* isolate,
header_string_len);
// Make sure the start address is aligned appropriately for an nghttp2_nv*.
char* start = reinterpret_cast<char*>(
ROUND_UP(reinterpret_cast<uintptr_t>(*buf_), alignof(nghttp2_nv)));
RoundUp(reinterpret_cast<uintptr_t>(*buf_), alignof(nghttp2_nv)));
char* header_contents = start + (count_ * sizeof(nghttp2_nv));
nghttp2_nv* const nva = reinterpret_cast<nghttp2_nv*>(start);

Expand Down Expand Up @@ -438,8 +438,8 @@ Origins::Origins(Isolate* isolate,

// Make sure the start address is aligned appropriately for an nghttp2_nv*.
char* start = reinterpret_cast<char*>(
ROUND_UP(reinterpret_cast<uintptr_t>(*buf_),
alignof(nghttp2_origin_entry)));
RoundUp(reinterpret_cast<uintptr_t>(*buf_),
alignof(nghttp2_origin_entry)));
char* origin_contents = start + (count_ * sizeof(nghttp2_origin_entry));
nghttp2_origin_entry* const nva =
reinterpret_cast<nghttp2_origin_entry*>(start);
Expand Down
4 changes: 2 additions & 2 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ Maybe<int> SyncProcessRunner::CopyJsStringArray(Local<Value> js_value,
Maybe<size_t> maybe_size = StringBytes::StorageSize(isolate, value, UTF8);
if (maybe_size.IsNothing()) return Nothing<int>();
data_size += maybe_size.FromJust() + 1;
data_size = ROUND_UP(data_size, sizeof(void*));
data_size = RoundUp(data_size, sizeof(void*));
}

buffer = new char[list_size + data_size];
Expand All @@ -1068,7 +1068,7 @@ Maybe<int> SyncProcessRunner::CopyJsStringArray(Local<Value> js_value,
value,
UTF8);
buffer[data_offset++] = '\0';
data_offset = ROUND_UP(data_offset, sizeof(void*));
data_offset = RoundUp(data_offset, sizeof(void*));
}

list[length] = nullptr;
Expand Down
8 changes: 5 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,11 @@ constexpr size_t arraysize(const T (&)[N]) {
return N;
}

#ifndef ROUND_UP
#define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
#endif
// Round up a to the next highest multiple of b.
template <typename T>
constexpr T RoundUp(T a, T b) {
return a % b != 0 ? a + b - (a % b) : a;
}

#ifdef __GNUC__
#define MUST_USE_RESULT __attribute__((warn_unused_result))
Expand Down