| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, | 274 Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, |
| 275 PretenureFlag pretenure) { | 275 PretenureFlag pretenure) { |
| 276 CALL_HEAP_FUNCTION( | 276 CALL_HEAP_FUNCTION( |
| 277 isolate(), | 277 isolate(), |
| 278 isolate()->heap()->AllocateStringFromOneByte(string, pretenure), | 278 isolate()->heap()->AllocateStringFromOneByte(string, pretenure), |
| 279 String); | 279 String); |
| 280 } | 280 } |
| 281 | 281 |
| 282 Handle<String> Factory::NewStringFromUtf8(Vector<const char> string, | 282 Handle<String> Factory::NewStringFromUtf8(Vector<const char> string, |
| 283 PretenureFlag pretenure) { | 283 PretenureFlag pretenure) { |
| 284 // Check for ASCII first since this is the common case. |
| 285 const char* start = string.start(); |
| 286 int length = string.length(); |
| 287 int non_ascii_start = String::NonAsciiStart(start, length); |
| 288 if (non_ascii_start >= length) { |
| 289 // If the string is ASCII, we do not need to convert the characters |
| 290 // since UTF8 is backwards compatible with ASCII. |
| 291 return NewStringFromOneByte(Vector<const uint8_t>::cast(string), pretenure); |
| 292 } |
| 293 // Non-ASCII and we need to decode. |
| 284 CALL_HEAP_FUNCTION( | 294 CALL_HEAP_FUNCTION( |
| 285 isolate(), | 295 isolate(), |
| 286 isolate()->heap()->AllocateStringFromUtf8(string, pretenure), | 296 isolate()->heap()->AllocateStringFromUtf8Slow(string, |
| 297 non_ascii_start, |
| 298 pretenure), |
| 287 String); | 299 String); |
| 288 } | 300 } |
| 289 | 301 |
| 290 | 302 |
| 291 Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string, | 303 Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string, |
| 292 PretenureFlag pretenure) { | 304 PretenureFlag pretenure) { |
| 293 CALL_HEAP_FUNCTION( | 305 CALL_HEAP_FUNCTION( |
| 294 isolate(), | 306 isolate(), |
| 295 isolate()->heap()->AllocateStringFromTwoByte(string, pretenure), | 307 isolate()->heap()->AllocateStringFromTwoByte(string, pretenure), |
| 296 String); | 308 String); |
| (...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2330 if (String::Equals(name, infinity_string())) return infinity_value(); | 2342 if (String::Equals(name, infinity_string())) return infinity_value(); |
| 2331 return Handle<Object>::null(); | 2343 return Handle<Object>::null(); |
| 2332 } | 2344 } |
| 2333 | 2345 |
| 2334 | 2346 |
| 2335 Handle<Object> Factory::ToBoolean(bool value) { | 2347 Handle<Object> Factory::ToBoolean(bool value) { |
| 2336 return value ? true_value() : false_value(); | 2348 return value ? true_value() : false_value(); |
| 2337 } | 2349 } |
| 2338 | 2350 |
| 2339 } } // namespace v8::internal | 2351 } } // namespace v8::internal |
| OLD | NEW |