Skip to content

Commit

Permalink
src: turn ROUND_UP into an inline function
Browse files Browse the repository at this point in the history
PR-URL: #25743
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
  • Loading branch information
addaleax committed Jan 30, 2019
1 parent 23d51a1 commit 6f217e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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

0 comments on commit 6f217e7

Please sign in to comment.