Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryon Leung <teslaslegacy@gmail.com>2015-10-07 20:47:57 +0300
committerBen Noordhuis <info@bnoordhuis.nl>2015-11-24 17:26:23 +0300
commit2ccde01980f8577fbe36130689e6a85653989f51 (patch)
tree0f72ecc8fc6247be68177ebe15a0baa03c7a634b /src/util-inl.h
parent8bc80386879538de63cd6f2aef288f59324eb004 (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.h14
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_