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

Side by Side Diff: src/objects-inl.h

Issue 2577143002: [runtime] Add PositiveNumberToUint32 helper to avoid double to uint roundtrip (Closed)
Patch Set: avoid overflows Created 4 years 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
« no previous file with comments | « src/objects.cc ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 // Review notes: 5 // Review notes:
6 // 6 //
7 // - The use of macros in these inline functions may seem superfluous 7 // - The use of macros in these inline functions may seem superfluous
8 // but it is absolutely needed to make sure gcc generates optimal 8 // but it is absolutely needed to make sure gcc generates optimal
9 // code. gcc is not happy when attempting to inline too deep. 9 // code. gcc is not happy when attempting to inline too deep.
10 // 10 //
(...skipping 3835 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 } 3846 }
3847 3847
3848 3848
3849 template <> 3849 template <>
3850 inline Vector<const uc16> String::GetCharVector() { 3850 inline Vector<const uc16> String::GetCharVector() {
3851 String::FlatContent flat = GetFlatContent(); 3851 String::FlatContent flat = GetFlatContent();
3852 DCHECK(flat.IsTwoByte()); 3852 DCHECK(flat.IsTwoByte());
3853 return flat.ToUC16Vector(); 3853 return flat.ToUC16Vector();
3854 } 3854 }
3855 3855
3856 uint32_t String::ToValidIndex(Object* number) {
3857 uint32_t index = PositiveNumberToUint32(number);
3858 uint32_t length_value = static_cast<uint32_t>(length());
3859 if (index > length_value) return length_value;
3860 return index;
3861 }
3856 3862
3857 uint16_t SeqOneByteString::SeqOneByteStringGet(int index) { 3863 uint16_t SeqOneByteString::SeqOneByteStringGet(int index) {
3858 DCHECK(index >= 0 && index < length()); 3864 DCHECK(index >= 0 && index < length());
3859 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); 3865 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize);
3860 } 3866 }
3861 3867
3862 3868
3863 void SeqOneByteString::SeqOneByteStringSet(int index, uint16_t value) { 3869 void SeqOneByteString::SeqOneByteStringSet(int index, uint16_t value) {
3864 DCHECK(index >= 0 && index < length() && value <= kMaxOneByteCharCode); 3870 DCHECK(index >= 0 && index < length() && value <= kMaxOneByteCharCode);
3865 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, 3871 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize,
(...skipping 4619 matching lines...) Expand 10 before | Expand all | Expand 10 after
8485 #undef WRITE_INT64_FIELD 8491 #undef WRITE_INT64_FIELD
8486 #undef READ_BYTE_FIELD 8492 #undef READ_BYTE_FIELD
8487 #undef WRITE_BYTE_FIELD 8493 #undef WRITE_BYTE_FIELD
8488 #undef NOBARRIER_READ_BYTE_FIELD 8494 #undef NOBARRIER_READ_BYTE_FIELD
8489 #undef NOBARRIER_WRITE_BYTE_FIELD 8495 #undef NOBARRIER_WRITE_BYTE_FIELD
8490 8496
8491 } // namespace internal 8497 } // namespace internal
8492 } // namespace v8 8498 } // namespace v8
8493 8499
8494 #endif // V8_OBJECTS_INL_H_ 8500 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698