Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Isolate* isolate, | |
|
siva
2012/12/04 03:04:50
Isolate is passed in here and not used at all, why
srdjan
2012/12/04 21:41:30
Removed.
| |
| 10743 Heap::Space space) { | |
| 10744 ASSERT(!str.IsNull() && str.IsOneByteString()); | |
| 10745 ASSERT(begin_index >= 0); | |
| 10746 ASSERT(length >= 0); | |
| 10747 if (begin_index <= str.Length() && length == 0) { | |
| 10748 return OneByteString::raw(String::Handle(Symbols::Empty())); | |
| 10749 } | |
| 10750 ASSERT(begin_index < str.Length()); | |
| 10751 RawOneByteString* result = OneByteString::New(length, space); | |
| 10752 NoGCScope no_gc; | |
| 10753 if (length > 0) { | |
| 10754 uint8_t* dest = &result->ptr()->data_[0]; | |
| 10755 uint8_t* src = &raw_ptr(str)->data_[begin_index]; | |
| 10756 memmove(dest, src, length); | |
| 10757 } | |
| 10758 return result; | |
| 10759 } | |
| 10760 | |
| 10761 | |
| 10739 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, | 10762 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, |
| 10740 bool raw_str) { | 10763 bool raw_str) { |
| 10741 intptr_t len = str.Length(); | 10764 intptr_t len = str.Length(); |
| 10742 if (len > 0) { | 10765 if (len > 0) { |
| 10743 intptr_t num_escapes = 0; | 10766 intptr_t num_escapes = 0; |
| 10744 intptr_t index = 0; | 10767 intptr_t index = 0; |
| 10745 for (intptr_t i = 0; i < len; i++) { | 10768 for (intptr_t i = 0; i < len; i++) { |
| 10746 if (IsSpecialCharacter(*CharAddr(str, i)) || | 10769 if (IsSpecialCharacter(*CharAddr(str, i)) || |
| 10747 (!raw_str && (*CharAddr(str, i) == '\\'))) { | 10770 (!raw_str && (*CharAddr(str, i) == '\\'))) { |
| 10748 num_escapes += 1; | 10771 num_escapes += 1; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11135 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); | 11158 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); |
| 11136 } | 11159 } |
| 11137 | 11160 |
| 11138 | 11161 |
| 11139 const char* ImmutableArray::ToCString() const { | 11162 const char* ImmutableArray::ToCString() const { |
| 11140 return "ImmutableArray"; | 11163 return "ImmutableArray"; |
| 11141 } | 11164 } |
| 11142 | 11165 |
| 11143 | 11166 |
| 11144 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { | 11167 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { |
| 11168 Add(value, Isolate::Current(), space); | |
| 11169 } | |
| 11170 | |
| 11171 | |
| 11172 void GrowableObjectArray::Add(const Object& value, | |
| 11173 Isolate* isolate, | |
| 11174 Heap::Space space) const { | |
| 11145 ASSERT(!IsNull()); | 11175 ASSERT(!IsNull()); |
| 11146 Array& contents = Array::Handle(data()); | 11176 Array& contents = Array::Handle(isolate, data()); |
| 11147 if (Length() == Capacity()) { | 11177 if (Length() == Capacity()) { |
| 11148 // TODO(Issue 2500): Need a better growth strategy. | 11178 // TODO(Issue 2500): Need a better growth strategy. |
| 11149 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; | 11179 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; |
| 11150 if (new_capacity <= Capacity()) { | 11180 if (new_capacity <= Capacity()) { |
| 11151 // Use the preallocated out of memory exception to avoid calling | 11181 // Use the preallocated out of memory exception to avoid calling |
| 11152 // into dart code or allocating any code. | 11182 // into dart code or allocating any code. |
| 11153 const Instance& exception = | 11183 const Instance& exception = |
| 11154 Instance::Handle(Isolate::Current()->object_store()->out_of_memory()); | 11184 Instance::Handle(isolate->object_store()->out_of_memory()); |
| 11155 Exceptions::Throw(exception); | 11185 Exceptions::Throw(exception); |
| 11156 UNREACHABLE(); | 11186 UNREACHABLE(); |
| 11157 } | 11187 } |
| 11158 Grow(new_capacity, space); | 11188 Grow(new_capacity, space); |
| 11159 contents = data(); | 11189 contents = data(); |
| 11160 } | 11190 } |
| 11161 ASSERT(Length() < Capacity()); | 11191 ASSERT(Length() < Capacity()); |
| 11162 intptr_t index = Length(); | 11192 intptr_t index = Length(); |
| 11163 SetLength(index + 1); | 11193 SetLength(index + 1); |
| 11164 contents.SetAt(index, value); | 11194 contents.SetAt(index, value); |
|
siva
2012/12/04 03:04:50
Instead of passing in the isolate maybe we should
srdjan
2012/12/04 21:41:30
Good idea. Discussed and Siva will take a look at
| |
| 11165 } | 11195 } |
| 11166 | 11196 |
| 11167 | 11197 |
| 11168 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const { | 11198 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const { |
| 11169 ASSERT(new_capacity > Capacity()); | 11199 ASSERT(new_capacity > Capacity()); |
| 11170 const Array& contents = Array::Handle(data()); | 11200 const Array& contents = Array::Handle(data()); |
| 11171 const Array& new_contents = | 11201 const Array& new_contents = |
| 11172 Array::Handle(Array::Grow(contents, new_capacity, space)); | 11202 Array::Handle(Array::Grow(contents, new_capacity, space)); |
| 11173 StorePointer(&(raw_ptr()->data_), new_contents.raw()); | 11203 StorePointer(&(raw_ptr()->data_), new_contents.raw()); |
| 11174 ASSERT(AbstractTypeArguments::AreEqual( | 11204 ASSERT(AbstractTypeArguments::AreEqual( |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12083 } | 12113 } |
| 12084 return result.raw(); | 12114 return result.raw(); |
| 12085 } | 12115 } |
| 12086 | 12116 |
| 12087 | 12117 |
| 12088 const char* WeakProperty::ToCString() const { | 12118 const char* WeakProperty::ToCString() const { |
| 12089 return "_WeakProperty"; | 12119 return "_WeakProperty"; |
| 12090 } | 12120 } |
| 12091 | 12121 |
| 12092 } // namespace dart | 12122 } // namespace dart |
| OLD | NEW |