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

Unified Diff: src/objects-inl.h

Issue 1014005: Attempt at pre-calculating replace regexp matches. (Closed)
Patch Set: Reuse result array. Avoid using apply. Created 10 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/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 4cc9b9f8340238549a12136218672eb205771007..33f89439e64aeb40d768df69a97393512cfa9cbe 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -3025,6 +3025,38 @@ void Map::ClearCodeCache() {
}
+void JSArray::Resize(int required_size) {
+ ASSERT(HasFastElements());
+ int current_length = Smi::cast(this->length())->value();
+ Array* elts = elements();
+ if (required_size < current_length) {
+ // Set length before potentially expanding. If a new backing array is
+ // allocated, we will only copy the data below the new length.
+ this->set_length(Smi::FromInt(required_size));
+ }
+ const int kArraySizeThatFitsComfortablyInNewSpace = 128;
+ if (elts->length() < required_size) {
+ // Doubling in size would be overkill, but leave some slack to avoid
+ // constantly growing.
+ Expand(required_size + (required_size >> 3));
+ // It's a performance benefit to keep a frequently used array in new-space.
+ } else if (!Heap::InNewSpace(elts) &&
+ required_size < kArraySizeThatFitsComfortablyInNewSpace) {
+ // Expand will allocate a new backing store in new space even if the size
+ // we asked for isn't larger than what we had before.
+ Expand(required_size);
+ } else {
+ // Using same backing store.
+ if (current_length > required_size) {
+ for (int i = required_size; i < current_length; i++) {
+ FixedArray::cast(elts)->set_the_hole(i);
+ }
+ return;
+ }
+ }
+}
+
+
void JSArray::EnsureSize(int required_size) {
ASSERT(HasFastElements());
Array* elts = elements();
« no previous file with comments | « src/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698