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

Unified Diff: src/runtime.cc

Issue 1709008: Introduce faster swapping primitives. (Closed)
Patch Set: Stub ports to x64 and ARM Created 10 years, 8 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/runtime.h ('k') | src/x64/codegen-x64.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index dd0a3d2a0dbb65390c05c76282407dbff04830ad..e2ff7f41240f064df2e192dd09fd5197cb1fb365 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -7748,6 +7748,38 @@ static Object* Runtime_EstimateNumberOfElements(Arguments args) {
}
+static Object* Runtime_SwapElements(Arguments args) {
+ HandleScope handle_scope;
+
+ ASSERT_EQ(3, args.length());
+
+ Handle<Object> object = args.at<Object>(0);
+ Handle<Object> key1 = args.at<Object>(1);
+ Handle<Object> key2 = args.at<Object>(2);
+
+ uint32_t index1, index2;
+ // That must be the most common case.
+ if (object->IsJSObject()
+ && Array::IndexFromObject(*key1, &index1)
+ && Array::IndexFromObject(*key2, &index2)) {
+ Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
+ Handle<Object> tmp1 = GetElement(jsobject, index1);
+ Handle<Object> tmp2 = GetElement(jsobject, index2);
+
+ SetElement(jsobject, index1, tmp2);
+ SetElement(jsobject, index2, tmp1);
+ } else {
+ Handle<Object> tmp1 = GetProperty(object, key1);
+ Handle<Object> tmp2 = GetProperty(object, key2);
+
+ SetProperty(object, key1, tmp2, NONE);
+ SetProperty(object, key2, tmp1, NONE);
+ }
+
+ return Heap::undefined_value();
+}
+
+
// Returns an array that tells you where in the [0, length) interval an array
// might have elements. Can either return keys or intervals. Keys can have
// gaps in (undefined). Intervals can also span over some undefined keys.
« no previous file with comments | « src/runtime.h ('k') | src/x64/codegen-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698