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

Side by Side Diff: src/utils.h

Issue 650058: Improve string runtime compare performance for flat strings. (Closed)
Patch Set: Created 10 years, 10 months 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
« src/runtime.cc ('K') | « src/runtime.cc ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); 521 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
522 }; 522 };
523 523
524 524
525 // Copy from ASCII/16bit chars to ASCII/16bit chars. 525 // Copy from ASCII/16bit chars to ASCII/16bit chars.
526 template <typename sourcechar, typename sinkchar> 526 template <typename sourcechar, typename sinkchar>
527 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { 527 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) {
528 sinkchar* limit = dest + chars; 528 sinkchar* limit = dest + chars;
529 #ifdef V8_HOST_CAN_READ_UNALIGNED 529 #ifdef V8_HOST_CAN_READ_UNALIGNED
530 if (sizeof(*dest) == sizeof(*src)) { 530 if (sizeof(*dest) == sizeof(*src)) {
531 // Number of characters in a uint32_t. 531 // Number of characters in a uintptr_t.
532 static const int kStepSize = sizeof(uint32_t) / sizeof(*dest); // NOLINT 532 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT
533 while (dest <= limit - kStepSize) { 533 while (dest <= limit - kStepSize) {
534 *reinterpret_cast<uint32_t*>(dest) = 534 *reinterpret_cast<uintptr_t*>(dest) =
535 *reinterpret_cast<const uint32_t*>(src); 535 *reinterpret_cast<const uintptr_t*>(src);
536 dest += kStepSize; 536 dest += kStepSize;
537 src += kStepSize; 537 src += kStepSize;
538 } 538 }
539 } 539 }
540 #endif 540 #endif
541 while (dest < limit) { 541 while (dest < limit) {
542 *dest++ = static_cast<sinkchar>(*src++); 542 *dest++ = static_cast<sinkchar>(*src++);
543 } 543 }
544 } 544 }
545 545
546 546
547 // Compare ASCII/16bit chars to ASCII/16bit chars.
548 template <typename lchar, typename rchar>
549 static inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) {
550 const lchar* limit = lhs + chars;
551 #ifdef V8_HOST_CAN_READ_UNALIGNED
552 if (sizeof(*lhs) == sizeof(*rhs)) {
553 // Number of characters in a uintptr_t.
554 static const int kStepSize = sizeof(uintptr_t) / sizeof(*lhs); // NOLINT
555 while (lhs <= limit - kStepSize) {
556 if (*reinterpret_cast<const uintptr_t*>(lhs) !=
557 *reinterpret_cast<const uintptr_t*>(rhs)) {
558 break;
559 }
560 lhs += kStepSize;
561 rhs += kStepSize;
562 }
563 }
564 #endif
565 while (lhs < limit) {
566 int r = static_cast<int>(*lhs) - static_cast<int>(*rhs);
567 if (r != 0) return r;
568 ++lhs;
569 ++rhs;
570 }
571 return 0;
572 }
573
574
547 // Calculate 10^exponent. 575 // Calculate 10^exponent.
548 int TenToThe(int exponent); 576 int TenToThe(int exponent);
549 577
550 } } // namespace v8::internal 578 } } // namespace v8::internal
551 579
552 #endif // V8_UTILS_H_ 580 #endif // V8_UTILS_H_
OLDNEW
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698