diff options
author | Bryon Leung <teslaslegacy@gmail.com> | 2015-10-07 20:47:57 +0300 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-11-24 17:26:23 +0300 |
commit | 2ccde01980f8577fbe36130689e6a85653989f51 (patch) | |
tree | 0f72ecc8fc6247be68177ebe15a0baa03c7a634b /src/util-inl.h | |
parent | 8bc80386879538de63cd6f2aef288f59324eb004 (diff) |
src: add BE support to StringBytes::Encode()
Versions of Node.js after v0.12 have relocated byte-swapping away from
the StringBytes::Encode function, thereby causing a nan test (which
accesses this function directly) to fail on big-endian machines.
This change re-introduces byte swapping in StringBytes::Encode,
done via a call to a function in util-inl. Another change in
NodeBuffer::StringSlice was necessary to avoid double byte swapping
in big-endian function calls to StringSlice.
PR-URL: https://github.com/nodejs/node/pull/3410
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src/util-inl.h')
-rw-r--r-- | src/util-inl.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util-inl.h b/src/util-inl.h index 75bdb4784aa..669b7e75358 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -198,6 +198,20 @@ TypeName* Unwrap(v8::Local<v8::Object> object) { return static_cast<TypeName*>(pointer); } +void SwapBytes(uint16_t* dst, const uint16_t* src, size_t buflen) { + for (size_t i = 0; i < buflen; i++) { + // __builtin_bswap16 generates more efficient code with + // g++ 4.8 on PowerPC and other big-endian archs +#ifdef __GNUC__ + dst[i] = __builtin_bswap16(src[i]); +#else + dst[i] = (src[i] << 8) | (src[i] >> 8); +#endif + } +} + + + } // namespace node #endif // SRC_UTIL_INL_H_ |