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

Side by Side Diff: src/utils.h

Issue 390004: Fix warnings on Win64. (Closed)
Patch Set: Created 11 years, 1 month 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/api.cc ('K') | « src/spaces.cc ('k') | src/utils.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 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 static inline intptr_t OffsetFrom(T x) { 59 static inline intptr_t OffsetFrom(T x) {
60 return x - static_cast<T>(0); 60 return x - static_cast<T>(0);
61 } 61 }
62 62
63 63
64 // Compute the absolute value of type T for some 0-relative offset x. 64 // Compute the absolute value of type T for some 0-relative offset x.
65 // This allows conversion of 0-relative int offsets into Addresses and 65 // This allows conversion of 0-relative int offsets into Addresses and
66 // integral types. 66 // integral types.
67 template <typename T> 67 template <typename T>
68 static inline T AddressFrom(intptr_t x) { 68 static inline T AddressFrom(intptr_t x) {
69 return static_cast<T>(0) + x; 69 return static_cast<T>(static_cast<T>(0) + x);
70 } 70 }
71 71
72 72
73 // Return the largest multiple of m which is <= x. 73 // Return the largest multiple of m which is <= x.
74 template <typename T> 74 template <typename T>
75 static inline T RoundDown(T x, int m) { 75 static inline T RoundDown(T x, int m) {
76 ASSERT(IsPowerOf2(m)); 76 ASSERT(IsPowerOf2(m));
77 return AddressFrom<T>(OffsetFrom(x) & -m); 77 return AddressFrom<T>(OffsetFrom(x) & -m);
78 } 78 }
79 79
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 132
133 // Returns the minimum of the two parameters. 133 // Returns the minimum of the two parameters.
134 template <typename T> 134 template <typename T>
135 static T Min(T a, T b) { 135 static T Min(T a, T b) {
136 return a < b ? a : b; 136 return a < b ? a : b;
137 } 137 }
138 138
139 139
140 inline int StrLength(const char* string) {
141 size_t length = strlen(string);
142 ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
143 return static_cast<int>(length);
144 }
145
146
140 // ---------------------------------------------------------------------------- 147 // ----------------------------------------------------------------------------
141 // BitField is a help template for encoding and decode bitfield with 148 // BitField is a help template for encoding and decode bitfield with
142 // unsigned content. 149 // unsigned content.
143 template<class T, int shift, int size> 150 template<class T, int shift, int size>
144 class BitField { 151 class BitField {
145 public: 152 public:
146 // Tells whether the provided value fits into the bit field. 153 // Tells whether the provided value fits into the bit field.
147 static bool is_valid(T value) { 154 static bool is_valid(T value) {
148 return (static_cast<uint32_t>(value) & ~((1U << (size)) - 1)) == 0; 155 return (static_cast<uint32_t>(value) & ~((1U << (size)) - 1)) == 0;
149 } 156 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 class ScopedVector : public Vector<T> { 449 class ScopedVector : public Vector<T> {
443 public: 450 public:
444 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { } 451 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { }
445 ~ScopedVector() { 452 ~ScopedVector() {
446 DeleteArray(this->start()); 453 DeleteArray(this->start());
447 } 454 }
448 }; 455 };
449 456
450 457
451 inline Vector<const char> CStrVector(const char* data) { 458 inline Vector<const char> CStrVector(const char* data) {
452 return Vector<const char>(data, static_cast<int>(strlen(data))); 459 return Vector<const char>(data, StrLength(data));
453 } 460 }
454 461
455 inline Vector<char> MutableCStrVector(char* data) { 462 inline Vector<char> MutableCStrVector(char* data) {
456 return Vector<char>(data, static_cast<int>(strlen(data))); 463 return Vector<char>(data, StrLength(data));
457 } 464 }
458 465
459 inline Vector<char> MutableCStrVector(char* data, int max) { 466 inline Vector<char> MutableCStrVector(char* data, int max) {
460 int length = static_cast<int>(strlen(data)); 467 int length = StrLength(data);
461 return Vector<char>(data, (length < max) ? length : max); 468 return Vector<char>(data, (length < max) ? length : max);
462 } 469 }
463 470
464 template <typename T> 471 template <typename T>
465 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms, 472 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms,
466 int length) { 473 int length) {
467 return Vector< Handle<Object> >( 474 return Vector< Handle<Object> >(
468 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length); 475 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length);
469 } 476 }
470 477
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 #endif 580 #endif
574 while (dest < limit) { 581 while (dest < limit) {
575 *dest++ = static_cast<sinkchar>(*src++); 582 *dest++ = static_cast<sinkchar>(*src++);
576 } 583 }
577 } 584 }
578 585
579 586
580 } } // namespace v8::internal 587 } } // namespace v8::internal
581 588
582 #endif // V8_UTILS_H_ 589 #endif // V8_UTILS_H_
OLDNEW
« src/api.cc ('K') | « src/spaces.cc ('k') | src/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698