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

Side by Side Diff: src/runtime.cc

Issue 7782025: Optimize the common obfuscator pattern where ["foo","bar","baz"] (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 5966 matching lines...) Expand 10 before | Expand all | Expand 10 after
5977 ASSERT(args.length() == 3); 5977 ASSERT(args.length() == 3);
5978 HandleScope handle_scope(isolate); 5978 HandleScope handle_scope(isolate);
5979 CONVERT_ARG_CHECKED(String, subject, 0); 5979 CONVERT_ARG_CHECKED(String, subject, 0);
5980 CONVERT_ARG_CHECKED(String, pattern, 1); 5980 CONVERT_ARG_CHECKED(String, pattern, 1);
5981 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); 5981 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]);
5982 5982
5983 int subject_length = subject->length(); 5983 int subject_length = subject->length();
5984 int pattern_length = pattern->length(); 5984 int pattern_length = pattern->length();
5985 RUNTIME_ASSERT(pattern_length > 0); 5985 RUNTIME_ASSERT(pattern_length > 0);
5986 5986
5987 if (limit == 0xffffffffu) {
5988 Handle<Object> cached_answer(StringSplitCache::Lookup(
5989 isolate->heap()->string_split_cache(),
5990 *subject,
5991 *pattern));
5992 if (*cached_answer != Smi::FromInt(0)) {
5993 Handle<JSArray> result =
5994 isolate->factory()->NewJSArrayWithElements(
5995 Handle<FixedArray>::cast(cached_answer));
5996 return *result;
5997 }
5998 }
5999
5987 // The limit can be very large (0xffffffffu), but since the pattern 6000 // The limit can be very large (0xffffffffu), but since the pattern
5988 // isn't empty, we can never create more parts than ~half the length 6001 // isn't empty, we can never create more parts than ~half the length
5989 // of the subject. 6002 // of the subject.
5990 6003
5991 if (!subject->IsFlat()) FlattenString(subject); 6004 if (!subject->IsFlat()) FlattenString(subject);
5992 6005
5993 static const int kMaxInitialListCapacity = 16; 6006 static const int kMaxInitialListCapacity = 16;
5994 6007
5995 ZoneScope scope(isolate, DELETE_ON_EXIT); 6008 ZoneScope scope(isolate, DELETE_ON_EXIT);
5996 6009
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
6070 int part_start = 0; 6083 int part_start = 0;
6071 for (int i = 0; i < part_count; i++) { 6084 for (int i = 0; i < part_count; i++) {
6072 HandleScope local_loop_handle; 6085 HandleScope local_loop_handle;
6073 int part_end = indices.at(i); 6086 int part_end = indices.at(i);
6074 Handle<String> substring = 6087 Handle<String> substring =
6075 isolate->factory()->NewProperSubString(subject, part_start, part_end); 6088 isolate->factory()->NewProperSubString(subject, part_start, part_end);
6076 elements->set(i, *substring); 6089 elements->set(i, *substring);
6077 part_start = part_end + pattern_length; 6090 part_start = part_end + pattern_length;
6078 } 6091 }
6079 6092
6093 if (limit == 0xffffffffu) {
6094 StringSplitCache::Enter(isolate->heap(),
6095 isolate->heap()->string_split_cache(),
6096 *subject,
6097 *pattern,
6098 *elements);
6099 }
6100
6080 return *result; 6101 return *result;
6081 } 6102 }
6082 6103
6083 6104
6084 // Copies ascii characters to the given fixed array looking up 6105 // Copies ascii characters to the given fixed array looking up
6085 // one-char strings in the cache. Gives up on the first char that is 6106 // one-char strings in the cache. Gives up on the first char that is
6086 // not in the cache and fills the remainder with smi zeros. Returns 6107 // not in the cache and fills the remainder with smi zeros. Returns
6087 // the length of the successfully copied prefix. 6108 // the length of the successfully copied prefix.
6088 static int CopyCachedAsciiCharsToArray(Heap* heap, 6109 static int CopyCachedAsciiCharsToArray(Heap* heap,
6089 const char* chars, 6110 const char* chars,
(...skipping 6911 matching lines...) Expand 10 before | Expand all | Expand 10 after
13001 } else { 13022 } else {
13002 // Handle last resort GC and make sure to allow future allocations 13023 // Handle last resort GC and make sure to allow future allocations
13003 // to grow the heap without causing GCs (if possible). 13024 // to grow the heap without causing GCs (if possible).
13004 isolate->counters()->gc_last_resort_from_js()->Increment(); 13025 isolate->counters()->gc_last_resort_from_js()->Increment();
13005 isolate->heap()->CollectAllGarbage(false); 13026 isolate->heap()->CollectAllGarbage(false);
13006 } 13027 }
13007 } 13028 }
13008 13029
13009 13030
13010 } } // namespace v8::internal 13031 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698