Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: src/elements.cc

Issue 2761453002: [typedarrays] Implement %TypedArray%.prototype.reverse in C++ (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/elements.h ('k') | src/js/array.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/elements.cc
diff --git a/src/elements.cc b/src/elements.cc
index 6258da399c6c7d1983e71a4e4cee87745b055353..fd440a54be129a7a1c02ed75312c97d88827f9e2 100644
--- a/src/elements.cc
+++ b/src/elements.cc
@@ -1261,6 +1261,10 @@ class ElementsAccessorBase : public ElementsAccessor {
return Subclass::LastIndexOfValueImpl(isolate, receiver, value, start_from);
}
+ static void ReverseImpl(JSObject* receiver) { UNREACHABLE(); }
+
+ void Reverse(JSObject* receiver) final { Subclass::ReverseImpl(receiver); }
+
static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store,
uint32_t entry) {
return entry;
@@ -3035,6 +3039,19 @@ class TypedElementsAccessor
} while (k-- != 0);
return Just<int64_t>(-1);
}
+
+ static void ReverseImpl(JSObject* receiver) {
+ DisallowHeapAllocation no_gc;
+ DCHECK(!WasNeutered(receiver));
+
+ BackingStore* elements = BackingStore::cast(receiver->elements());
+
+ uint32_t len = elements->length();
+ if (len == 0) return;
+
+ ctype* data = static_cast<ctype*>(elements->DataPtr());
+ std::reverse(data, data + len);
+ }
};
#define FIXED_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \
« no previous file with comments | « src/elements.h ('k') | src/js/array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698