diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-06-15 01:56:09 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-06-19 18:34:20 +0300 |
commit | 2899588f28f4d02a61a19ecc8454ddaf14c7b6b3 (patch) | |
tree | ed629baa1209ad1d4ec6ee844c694a0c8d73c7a0 /src/util-inl.h | |
parent | 563062eddf3ee9582730b6ef61c439b6cfb2d849 (diff) |
src: simplify alignment-handling code
Use a common function to handle alignment computations in
multiple places.
PR-URL: https://github.com/nodejs/node/pull/33884
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'src/util-inl.h')
-rw-r--r-- | src/util-inl.h | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/util-inl.h b/src/util-inl.h index 6b4bdfe034d..1af87d492ad 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -208,8 +208,7 @@ void SwapBytes16(char* data, size_t nbytes) { CHECK_EQ(nbytes % 2, 0); #if defined(_MSC_VER) - int align = reinterpret_cast<uintptr_t>(data) % sizeof(uint16_t); - if (align == 0) { + if (AlignUp(data, sizeof(uint16_t)) == data) { // MSVC has no strict aliasing, and is able to highly optimize this case. uint16_t* data16 = reinterpret_cast<uint16_t*>(data); size_t len16 = nbytes / sizeof(*data16); @@ -232,9 +231,8 @@ void SwapBytes32(char* data, size_t nbytes) { CHECK_EQ(nbytes % 4, 0); #if defined(_MSC_VER) - int align = reinterpret_cast<uintptr_t>(data) % sizeof(uint32_t); // MSVC has no strict aliasing, and is able to highly optimize this case. - if (align == 0) { + if (AlignUp(data, sizeof(uint32_t)) == data) { uint32_t* data32 = reinterpret_cast<uint32_t*>(data); size_t len32 = nbytes / sizeof(*data32); for (size_t i = 0; i < len32; i++) { @@ -256,8 +254,7 @@ void SwapBytes64(char* data, size_t nbytes) { CHECK_EQ(nbytes % 8, 0); #if defined(_MSC_VER) - int align = reinterpret_cast<uintptr_t>(data) % sizeof(uint64_t); - if (align == 0) { + if (AlignUp(data, sizeof(uint64_t)) == data) { // MSVC has no strict aliasing, and is able to highly optimize this case. uint64_t* data64 = reinterpret_cast<uint64_t*>(data); size_t len64 = nbytes / sizeof(*data64); |