Skip to content

Commit d9c2690

Browse files
committed
src: turn ROUND_UP into an inline function
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>
1 parent d463181 commit d9c2690

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/node_http2.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ Headers::Headers(Isolate* isolate,
382382
header_string_len);
383383
// Make sure the start address is aligned appropriately for an nghttp2_nv*.
384384
char* start = reinterpret_cast<char*>(
385-
ROUND_UP(reinterpret_cast<uintptr_t>(*buf_), alignof(nghttp2_nv)));
385+
RoundUp(reinterpret_cast<uintptr_t>(*buf_), alignof(nghttp2_nv)));
386386
char* header_contents = start + (count_ * sizeof(nghttp2_nv));
387387
nghttp2_nv* const nva = reinterpret_cast<nghttp2_nv*>(start);
388388

@@ -438,8 +438,8 @@ Origins::Origins(Isolate* isolate,
438438

439439
// Make sure the start address is aligned appropriately for an nghttp2_nv*.
440440
char* start = reinterpret_cast<char*>(
441-
ROUND_UP(reinterpret_cast<uintptr_t>(*buf_),
442-
alignof(nghttp2_origin_entry)));
441+
RoundUp(reinterpret_cast<uintptr_t>(*buf_),
442+
alignof(nghttp2_origin_entry)));
443443
char* origin_contents = start + (count_ * sizeof(nghttp2_origin_entry));
444444
nghttp2_origin_entry* const nva =
445445
reinterpret_cast<nghttp2_origin_entry*>(start);

src/spawn_sync.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ Maybe<int> SyncProcessRunner::CopyJsStringArray(Local<Value> js_value,
10491049
Maybe<size_t> maybe_size = StringBytes::StorageSize(isolate, value, UTF8);
10501050
if (maybe_size.IsNothing()) return Nothing<int>();
10511051
data_size += maybe_size.FromJust() + 1;
1052-
data_size = ROUND_UP(data_size, sizeof(void*));
1052+
data_size = RoundUp(data_size, sizeof(void*));
10531053
}
10541054

10551055
buffer = new char[list_size + data_size];
@@ -1066,7 +1066,7 @@ Maybe<int> SyncProcessRunner::CopyJsStringArray(Local<Value> js_value,
10661066
value,
10671067
UTF8);
10681068
buffer[data_offset++] = '\0';
1069-
data_offset = ROUND_UP(data_offset, sizeof(void*));
1069+
data_offset = RoundUp(data_offset, sizeof(void*));
10701070
}
10711071

10721072
list[length] = nullptr;

src/util.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,11 @@ constexpr size_t arraysize(const T (&)[N]) {
617617
return N;
618618
}
619619

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

624626
#ifdef __GNUC__
625627
#define MUST_USE_RESULT __attribute__((warn_unused_result))

0 commit comments

Comments
 (0)