OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 bool verbose = true); | 310 bool verbose = true); |
311 Vector<const char> ReadFile(FILE* file, | 311 Vector<const char> ReadFile(FILE* file, |
312 bool* exists, | 312 bool* exists, |
313 bool verbose = true); | 313 bool verbose = true); |
314 | 314 |
315 | 315 |
316 template <typename sourcechar, typename sinkchar> | 316 template <typename sourcechar, typename sinkchar> |
317 INLINE(static void CopyCharsUnsigned(sinkchar* dest, | 317 INLINE(static void CopyCharsUnsigned(sinkchar* dest, |
318 const sourcechar* src, | 318 const sourcechar* src, |
319 int chars)); | 319 int chars)); |
320 #if defined(V8_HOST_ARCH_ARM) | |
321 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); | |
322 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars)); | |
323 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); | |
324 #endif | |
320 | 325 |
321 // Copy from ASCII/16bit chars to ASCII/16bit chars. | 326 // Copy from ASCII/16bit chars to ASCII/16bit chars. |
322 template <typename sourcechar, typename sinkchar> | 327 template <typename sourcechar, typename sinkchar> |
323 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); | 328 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); |
324 | 329 |
325 template<typename sourcechar, typename sinkchar> | 330 template<typename sourcechar, typename sinkchar> |
326 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { | 331 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { |
327 ASSERT(sizeof(sourcechar) <= 2); | 332 ASSERT(sizeof(sourcechar) <= 2); |
328 ASSERT(sizeof(sinkchar) <= 2); | 333 ASSERT(sizeof(sinkchar) <= 2); |
329 if (sizeof(sinkchar) == 1) { | 334 if (sizeof(sinkchar) == 1) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 src += kStepSize; | 373 src += kStepSize; |
369 } | 374 } |
370 } | 375 } |
371 #endif | 376 #endif |
372 while (dest < limit) { | 377 while (dest < limit) { |
373 *dest++ = static_cast<sinkchar>(*src++); | 378 *dest++ = static_cast<sinkchar>(*src++); |
374 } | 379 } |
375 } | 380 } |
376 | 381 |
377 | 382 |
383 #if defined(V8_HOST_ARCH_ARM) | |
384 void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars) { | |
385 switch (static_cast<unsigned>(chars)) { | |
386 case 0: | |
387 break; | |
388 case 1: | |
389 *dest = *src; | |
390 break; | |
391 case 2: | |
392 memcpy(dest, src, 2); | |
393 break; | |
394 case 3: | |
395 memcpy(dest, src, 3); | |
396 break; | |
397 case 4: | |
398 memcpy(dest, src, 4); | |
399 break; | |
400 case 5: | |
401 memcpy(dest, src, 5); | |
402 break; | |
403 case 6: | |
404 memcpy(dest, src, 6); | |
405 break; | |
406 case 7: | |
407 memcpy(dest, src, 7); | |
408 break; | |
409 case 8: | |
410 memcpy(dest, src, 8); | |
411 break; | |
412 case 9: | |
413 memcpy(dest, src, 9); | |
414 break; | |
415 case 10: | |
416 memcpy(dest, src, 10); | |
417 break; | |
418 case 11: | |
419 memcpy(dest, src, 11); | |
420 break; | |
421 case 12: | |
422 memcpy(dest, src, 12); | |
423 break; | |
424 case 13: | |
425 memcpy(dest, src, 13); | |
426 break; | |
427 case 14: | |
428 memcpy(dest, src, 14); | |
429 break; | |
430 case 15: | |
431 memcpy(dest, src, 15); | |
ulan
2013/07/09 15:16:32
OK, if this gives perf. improvement compared to me
vincent.belliard.fr
2013/07/10 15:30:38
This gives good improvement. For small known sizes
| |
432 break; | |
433 default: | |
434 OS::MemCopy(dest, src, chars); | |
435 break; | |
436 } | |
437 } | |
438 | |
439 | |
440 void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars) { | |
441 if (chars >= OS::kMinComplexConvertMemCopy) { | |
442 OS::MemCopyUint16Uint8(dest, src, chars); | |
443 } else { | |
444 OS::MemCopyUint16Uint8Wrapper(dest, src, chars); | |
445 } | |
446 } | |
447 | |
448 | |
449 void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars) { | |
450 switch (static_cast<unsigned>(chars)) { | |
451 case 0: | |
452 break; | |
453 case 1: | |
454 *dest = *src; | |
455 break; | |
456 case 2: | |
457 memcpy(dest, src, 4); | |
458 break; | |
459 case 3: | |
460 memcpy(dest, src, 6); | |
461 break; | |
462 case 4: | |
463 memcpy(dest, src, 8); | |
464 break; | |
465 case 5: | |
466 memcpy(dest, src, 10); | |
467 break; | |
468 case 6: | |
469 memcpy(dest, src, 12); | |
470 break; | |
471 case 7: | |
472 memcpy(dest, src, 14); | |
473 break; | |
474 default: | |
475 OS::MemCopy(dest, src, chars * sizeof(*dest)); | |
476 break; | |
477 } | |
478 } | |
479 #endif | |
480 | |
481 | |
378 class StringBuilder : public SimpleStringBuilder { | 482 class StringBuilder : public SimpleStringBuilder { |
379 public: | 483 public: |
380 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } | 484 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } |
381 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } | 485 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } |
382 | 486 |
383 // Add formatted contents to the builder just like printf(). | 487 // Add formatted contents to the builder just like printf(). |
384 void AddFormatted(const char* format, ...); | 488 void AddFormatted(const char* format, ...); |
385 | 489 |
386 // Add formatted contents like printf based on a va_list. | 490 // Add formatted contents like printf based on a va_list. |
387 void AddFormattedList(const char* format, va_list list); | 491 void AddFormattedList(const char* format, va_list list); |
388 private: | 492 private: |
389 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 493 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
390 }; | 494 }; |
391 | 495 |
392 } } // namespace v8::internal | 496 } } // namespace v8::internal |
393 | 497 |
394 #endif // V8_V8UTILS_H_ | 498 #endif // V8_V8UTILS_H_ |
OLD | NEW |