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

Side by Side Diff: runtime/vm/object.cc

Issue 11308337: Improve C++ code for string splittig (Dromaeo benchmark). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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 | « runtime/vm/object.h ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 10718 matching lines...) Expand 10 before | Expand all | Expand 10 after
10729 const String& result = String::Handle(OneByteString::New(len, space)); 10729 const String& result = String::Handle(OneByteString::New(len, space));
10730 for (intptr_t i = 0; i < len; ++i) { 10730 for (intptr_t i = 0; i < len; ++i) {
10731 int32_t ch = mapping(str.CharAt(i)); 10731 int32_t ch = mapping(str.CharAt(i));
10732 ASSERT(Utf::IsLatin1(ch)); 10732 ASSERT(Utf::IsLatin1(ch));
10733 *CharAddr(result, i) = ch; 10733 *CharAddr(result, i) = ch;
10734 } 10734 }
10735 return OneByteString::raw(result); 10735 return OneByteString::raw(result);
10736 } 10736 }
10737 10737
10738 10738
10739 RawOneByteString* OneByteString::SubStringUnchecked(const String& str,
10740 intptr_t begin_index,
10741 intptr_t length,
10742 Heap::Space space) {
10743 ASSERT(!str.IsNull() && str.IsOneByteString());
10744 ASSERT(begin_index >= 0);
10745 ASSERT(length >= 0);
10746 if (begin_index <= str.Length() && length == 0) {
10747 return OneByteString::raw(String::Handle(Symbols::Empty()));
10748 }
10749 ASSERT(begin_index < str.Length());
10750 RawOneByteString* result = OneByteString::New(length, space);
10751 NoGCScope no_gc;
10752 if (length > 0) {
10753 uint8_t* dest = &result->ptr()->data_[0];
10754 uint8_t* src = &raw_ptr(str)->data_[begin_index];
10755 memmove(dest, src, length);
10756 }
10757 return result;
10758 }
10759
10760
10739 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, 10761 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str,
10740 bool raw_str) { 10762 bool raw_str) {
10741 intptr_t len = str.Length(); 10763 intptr_t len = str.Length();
10742 if (len > 0) { 10764 if (len > 0) {
10743 intptr_t num_escapes = 0; 10765 intptr_t num_escapes = 0;
10744 intptr_t index = 0; 10766 intptr_t index = 0;
10745 for (intptr_t i = 0; i < len; i++) { 10767 for (intptr_t i = 0; i < len; i++) {
10746 if (IsSpecialCharacter(*CharAddr(str, i)) || 10768 if (IsSpecialCharacter(*CharAddr(str, i)) ||
10747 (!raw_str && (*CharAddr(str, i) == '\\'))) { 10769 (!raw_str && (*CharAddr(str, i) == '\\'))) {
10748 num_escapes += 1; 10770 num_escapes += 1;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
11135 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); 11157 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space));
11136 } 11158 }
11137 11159
11138 11160
11139 const char* ImmutableArray::ToCString() const { 11161 const char* ImmutableArray::ToCString() const {
11140 return "ImmutableArray"; 11162 return "ImmutableArray";
11141 } 11163 }
11142 11164
11143 11165
11144 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { 11166 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const {
11167 Add(Isolate::Current(), value, space);
11168 }
11169
11170
11171 void GrowableObjectArray::Add(Isolate* isolate,
11172 const Object& value,
11173 Heap::Space space) const {
11145 ASSERT(!IsNull()); 11174 ASSERT(!IsNull());
11146 Array& contents = Array::Handle(data()); 11175 Array& contents = Array::Handle(isolate, data());
11147 if (Length() == Capacity()) { 11176 if (Length() == Capacity()) {
11148 // TODO(Issue 2500): Need a better growth strategy. 11177 // TODO(Issue 2500): Need a better growth strategy.
11149 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; 11178 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2;
11150 if (new_capacity <= Capacity()) { 11179 if (new_capacity <= Capacity()) {
11151 // Use the preallocated out of memory exception to avoid calling 11180 // Use the preallocated out of memory exception to avoid calling
11152 // into dart code or allocating any code. 11181 // into dart code or allocating any code.
11153 const Instance& exception = 11182 const Instance& exception =
11154 Instance::Handle(Isolate::Current()->object_store()->out_of_memory()); 11183 Instance::Handle(isolate->object_store()->out_of_memory());
11155 Exceptions::Throw(exception); 11184 Exceptions::Throw(exception);
11156 UNREACHABLE(); 11185 UNREACHABLE();
11157 } 11186 }
11158 Grow(new_capacity, space); 11187 Grow(new_capacity, space);
11159 contents = data(); 11188 contents = data();
11160 } 11189 }
11161 ASSERT(Length() < Capacity()); 11190 ASSERT(Length() < Capacity());
11162 intptr_t index = Length(); 11191 intptr_t index = Length();
11163 SetLength(index + 1); 11192 SetLength(index + 1);
11164 contents.SetAt(index, value); 11193 contents.SetAt(index, value);
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
12083 } 12112 }
12084 return result.raw(); 12113 return result.raw();
12085 } 12114 }
12086 12115
12087 12116
12088 const char* WeakProperty::ToCString() const { 12117 const char* WeakProperty::ToCString() const {
12089 return "_WeakProperty"; 12118 return "_WeakProperty";
12090 } 12119 }
12091 12120
12092 } // namespace dart 12121 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698