OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "macro-assembler.h" | 7 #include "macro-assembler.h" |
8 #include "isolate-inl.h" | 8 #include "isolate-inl.h" |
9 #include "v8conversions.h" | 9 #include "v8conversions.h" |
10 | 10 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 // Internalized strings are created in the old generation (data space). | 236 // Internalized strings are created in the old generation (data space). |
237 Handle<String> Factory::InternalizeUtf8String(Vector<const char> string) { | 237 Handle<String> Factory::InternalizeUtf8String(Vector<const char> string) { |
238 Utf8StringKey key(string, isolate()->heap()->HashSeed()); | 238 Utf8StringKey key(string, isolate()->heap()->HashSeed()); |
239 return InternalizeStringWithKey(&key); | 239 return InternalizeStringWithKey(&key); |
240 } | 240 } |
241 | 241 |
242 | 242 |
243 // Internalized strings are created in the old generation (data space). | 243 // Internalized strings are created in the old generation (data space). |
244 Handle<String> Factory::InternalizeString(Handle<String> string) { | 244 Handle<String> Factory::InternalizeString(Handle<String> string) { |
245 CALL_HEAP_FUNCTION(isolate(), | 245 if (string->IsInternalizedString()) return string; |
246 isolate()->heap()->InternalizeString(*string), | 246 return StringTable::LookupString(isolate(), string); |
247 String); | |
248 } | 247 } |
249 | 248 |
250 | 249 |
251 Handle<String> Factory::InternalizeOneByteString(Vector<const uint8_t> string) { | 250 Handle<String> Factory::InternalizeOneByteString(Vector<const uint8_t> string) { |
252 OneByteStringKey key(string, isolate()->heap()->HashSeed()); | 251 OneByteStringKey key(string, isolate()->heap()->HashSeed()); |
253 return InternalizeStringWithKey(&key); | 252 return InternalizeStringWithKey(&key); |
254 } | 253 } |
255 | 254 |
256 | 255 |
257 Handle<String> Factory::InternalizeOneByteString( | 256 Handle<String> Factory::InternalizeOneByteString( |
258 Handle<SeqOneByteString> string, int from, int length) { | 257 Handle<SeqOneByteString> string, int from, int length) { |
259 SubStringKey<uint8_t> key(string, from, length); | 258 SubStringKey<uint8_t> key(string, from, length); |
260 return InternalizeStringWithKey(&key); | 259 return InternalizeStringWithKey(&key); |
261 } | 260 } |
262 | 261 |
263 | 262 |
264 Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) { | 263 Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) { |
265 TwoByteStringKey key(string, isolate()->heap()->HashSeed()); | 264 TwoByteStringKey key(string, isolate()->heap()->HashSeed()); |
266 return InternalizeStringWithKey(&key); | 265 return InternalizeStringWithKey(&key); |
267 } | 266 } |
268 | 267 |
269 | 268 |
270 template<class StringTableKey> | 269 template<class StringTableKey> |
271 Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) { | 270 Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) { |
272 CALL_HEAP_FUNCTION(isolate(), | 271 return StringTable::LookupKey(isolate(), key); |
273 isolate()->heap()->InternalizeStringWithKey(key), | |
274 String); | |
275 } | 272 } |
276 | 273 |
277 | 274 |
278 template Handle<String> Factory::InternalizeStringWithKey< | 275 template Handle<String> Factory::InternalizeStringWithKey< |
279 SubStringKey<uint8_t> > (SubStringKey<uint8_t>* key); | 276 SubStringKey<uint8_t> > (SubStringKey<uint8_t>* key); |
280 template Handle<String> Factory::InternalizeStringWithKey< | 277 template Handle<String> Factory::InternalizeStringWithKey< |
281 SubStringKey<uint16_t> > (SubStringKey<uint16_t>* key); | 278 SubStringKey<uint16_t> > (SubStringKey<uint16_t>* key); |
282 | 279 |
283 | 280 |
284 MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, | 281 MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 340 |
344 MaybeHandle<SeqTwoByteString> Factory::NewRawTwoByteString( | 341 MaybeHandle<SeqTwoByteString> Factory::NewRawTwoByteString( |
345 int length, PretenureFlag pretenure) { | 342 int length, PretenureFlag pretenure) { |
346 CALL_HEAP_FUNCTION( | 343 CALL_HEAP_FUNCTION( |
347 isolate(), | 344 isolate(), |
348 isolate()->heap()->AllocateRawTwoByteString(length, pretenure), | 345 isolate()->heap()->AllocateRawTwoByteString(length, pretenure), |
349 SeqTwoByteString); | 346 SeqTwoByteString); |
350 } | 347 } |
351 | 348 |
352 | 349 |
353 Handle<String> Factory::LookupSingleCharacterStringFromCode(uint32_t index) { | 350 Handle<String> Factory::LookupSingleCharacterStringFromCode(uint32_t code) { |
354 CALL_HEAP_FUNCTION( | 351 if (code <= String::kMaxOneByteCharCodeU) { |
355 isolate(), | 352 { |
356 isolate()->heap()->LookupSingleCharacterStringFromCode(index), | 353 DisallowHeapAllocation no_allocation; |
357 String); | 354 Object* value = single_character_string_cache()->get(code); |
| 355 if (value != *undefined_value()) { |
| 356 return handle(String::cast(value), isolate()); |
| 357 } |
| 358 } |
| 359 uint8_t buffer[1]; |
| 360 buffer[0] = static_cast<uint8_t>(code); |
| 361 Handle<String> result = |
| 362 InternalizeOneByteString(Vector<const uint8_t>(buffer, 1)); |
| 363 single_character_string_cache()->set(code, *result); |
| 364 return result; |
| 365 } |
| 366 ASSERT(code <= String::kMaxUtf16CodeUnitU); |
| 367 |
| 368 Handle<SeqTwoByteString> result = NewRawTwoByteString(1).ToHandleChecked(); |
| 369 result->SeqTwoByteStringSet(0, static_cast<uint16_t>(code)); |
| 370 return result; |
358 } | 371 } |
359 | 372 |
360 | 373 |
361 // Returns true for a character in a range. Both limits are inclusive. | 374 // Returns true for a character in a range. Both limits are inclusive. |
362 static inline bool Between(uint32_t character, uint32_t from, uint32_t to) { | 375 static inline bool Between(uint32_t character, uint32_t from, uint32_t to) { |
363 // This makes uses of the the unsigned wraparound. | 376 // This makes uses of the the unsigned wraparound. |
364 return character - from <= to - from; | 377 return character - from <= to - from; |
365 } | 378 } |
366 | 379 |
367 | 380 |
(...skipping 1960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 return Handle<Object>::null(); | 2341 return Handle<Object>::null(); |
2329 } | 2342 } |
2330 | 2343 |
2331 | 2344 |
2332 Handle<Object> Factory::ToBoolean(bool value) { | 2345 Handle<Object> Factory::ToBoolean(bool value) { |
2333 return value ? true_value() : false_value(); | 2346 return value ? true_value() : false_value(); |
2334 } | 2347 } |
2335 | 2348 |
2336 | 2349 |
2337 } } // namespace v8::internal | 2350 } } // namespace v8::internal |
OLD | NEW |