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

Side by Side Diff: src/runtime.cc

Issue 1709008: Introduce faster swapping primitives. (Closed)
Patch Set: Stub ports to x64 and ARM Created 10 years, 7 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 unified diff | Download patch
« no previous file with comments | « src/runtime.h ('k') | src/x64/codegen-x64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 7730 matching lines...) Expand 10 before | Expand all | Expand 10 after
7741 CONVERT_CHECKED(JSArray, array, args[0]); 7741 CONVERT_CHECKED(JSArray, array, args[0]);
7742 HeapObject* elements = array->elements(); 7742 HeapObject* elements = array->elements();
7743 if (elements->IsDictionary()) { 7743 if (elements->IsDictionary()) {
7744 return Smi::FromInt(NumberDictionary::cast(elements)->NumberOfElements()); 7744 return Smi::FromInt(NumberDictionary::cast(elements)->NumberOfElements());
7745 } else { 7745 } else {
7746 return array->length(); 7746 return array->length();
7747 } 7747 }
7748 } 7748 }
7749 7749
7750 7750
7751 static Object* Runtime_SwapElements(Arguments args) {
7752 HandleScope handle_scope;
7753
7754 ASSERT_EQ(3, args.length());
7755
7756 Handle<Object> object = args.at<Object>(0);
7757 Handle<Object> key1 = args.at<Object>(1);
7758 Handle<Object> key2 = args.at<Object>(2);
7759
7760 uint32_t index1, index2;
7761 // That must be the most common case.
7762 if (object->IsJSObject()
7763 && Array::IndexFromObject(*key1, &index1)
7764 && Array::IndexFromObject(*key2, &index2)) {
7765 Handle<JSObject> jsobject = Handle<JSObject>::cast(object);
7766 Handle<Object> tmp1 = GetElement(jsobject, index1);
7767 Handle<Object> tmp2 = GetElement(jsobject, index2);
7768
7769 SetElement(jsobject, index1, tmp2);
7770 SetElement(jsobject, index2, tmp1);
7771 } else {
7772 Handle<Object> tmp1 = GetProperty(object, key1);
7773 Handle<Object> tmp2 = GetProperty(object, key2);
7774
7775 SetProperty(object, key1, tmp2, NONE);
7776 SetProperty(object, key2, tmp1, NONE);
7777 }
7778
7779 return Heap::undefined_value();
7780 }
7781
7782
7751 // Returns an array that tells you where in the [0, length) interval an array 7783 // Returns an array that tells you where in the [0, length) interval an array
7752 // might have elements. Can either return keys or intervals. Keys can have 7784 // might have elements. Can either return keys or intervals. Keys can have
7753 // gaps in (undefined). Intervals can also span over some undefined keys. 7785 // gaps in (undefined). Intervals can also span over some undefined keys.
7754 static Object* Runtime_GetArrayKeys(Arguments args) { 7786 static Object* Runtime_GetArrayKeys(Arguments args) {
7755 ASSERT(args.length() == 2); 7787 ASSERT(args.length() == 2);
7756 HandleScope scope; 7788 HandleScope scope;
7757 CONVERT_ARG_CHECKED(JSObject, array, 0); 7789 CONVERT_ARG_CHECKED(JSObject, array, 0);
7758 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); 7790 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]);
7759 if (array->elements()->IsDictionary()) { 7791 if (array->elements()->IsDictionary()) {
7760 // Create an array and get all the keys into it, then remove all the 7792 // Create an array and get all the keys into it, then remove all the
(...skipping 2440 matching lines...) Expand 10 before | Expand all | Expand 10 after
10201 } else { 10233 } else {
10202 // Handle last resort GC and make sure to allow future allocations 10234 // Handle last resort GC and make sure to allow future allocations
10203 // to grow the heap without causing GCs (if possible). 10235 // to grow the heap without causing GCs (if possible).
10204 Counters::gc_last_resort_from_js.Increment(); 10236 Counters::gc_last_resort_from_js.Increment();
10205 Heap::CollectAllGarbage(false); 10237 Heap::CollectAllGarbage(false);
10206 } 10238 }
10207 } 10239 }
10208 10240
10209 10241
10210 } } // namespace v8::internal 10242 } } // namespace v8::internal
OLDNEW
« 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