summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authortrav90 <travawine@palemoon.org>2018-09-19 19:05:22 -0500
committertrav90 <travawine@palemoon.org>2018-09-19 19:05:22 -0500
commit1343697efed32417c26e212bc440250a5f1fe0d3 (patch)
tree99497ee4009500def689345bf833b9105ac5e6e4 /js
parentadf77913604d0c4e04eff82ddac748b3398ec340 (diff)
downloaduxp-1343697efed32417c26e212bc440250a5f1fe0d3.tar.gz
Don't use PodCopy/PodMove to implement typed-array element-to-element copying
Standard std::copy and std::copy_n are readily optimized to the same thing, and they don't have a non-obvious requirement that the type being copied be trivial.
Diffstat (limited to 'js')
-rw-r--r--js/src/vm/TypedArrayCommon.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/js/src/vm/TypedArrayCommon.h b/js/src/vm/TypedArrayCommon.h
index d29c93a653..f59419b283 100644
--- a/js/src/vm/TypedArrayCommon.h
+++ b/js/src/vm/TypedArrayCommon.h
@@ -11,7 +11,8 @@
#include "mozilla/Assertions.h"
#include "mozilla/FloatingPoint.h"
-#include "mozilla/PodOperations.h"
+
+#include <algorithm>
#include "jsarray.h"
#include "jscntxt.h"
@@ -245,12 +246,24 @@ class UnsharedOps
template<typename T>
static void podCopy(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
- mozilla::PodCopy(dest.unwrapUnshared(), src.unwrapUnshared(), nelem);
+ // std::copy_n better matches the argument values/types of this
+ // function, but as noted below it allows the input/output ranges to
+ // overlap. std::copy does not, so use it so the compiler has extra
+ // ability to optimize.
+ const auto* first = src.unwrapUnshared();
+ const auto* last = first + nelem;
+ auto* result = dest.unwrapUnshared();
+ std::copy(first, last, result);
}
template<typename T>
- static void podMove(SharedMem<T*> dest, SharedMem<T*> src, size_t nelem) {
- mozilla::PodMove(dest.unwrapUnshared(), src.unwrapUnshared(), nelem);
+ static void podMove(SharedMem<T*> dest, SharedMem<T*> src, size_t n) {
+ // std::copy_n copies from |src| to |dest| starting from |src|, so
+ // input/output ranges *may* permissibly overlap, as this function
+ // allows.
+ const auto* start = src.unwrapUnshared();
+ auto* result = dest.unwrapUnshared();
+ std::copy_n(start, n, result);
}
static SharedMem<void*> extract(TypedArrayObject* obj) {