OLD | NEW |
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 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 #include <cmath> | 11 #include <cmath> |
12 | 12 |
13 #include "include/v8.h" | 13 #include "include/v8.h" |
14 #include "src/allocation.h" | 14 #include "src/allocation.h" |
15 #include "src/base/bits.h" | 15 #include "src/base/bits.h" |
16 #include "src/base/logging.h" | 16 #include "src/base/logging.h" |
17 #include "src/base/macros.h" | 17 #include "src/base/macros.h" |
18 #include "src/base/platform/platform.h" | 18 #include "src/base/platform/platform.h" |
19 #include "src/globals.h" | 19 #include "src/globals.h" |
20 #include "src/list.h" | 20 #include "src/list.h" |
21 #include "src/vector.h" | 21 #include "src/vector.h" |
22 | 22 |
23 namespace v8 { | 23 namespace v8 { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 // ---------------------------------------------------------------------------- | 26 // ---------------------------------------------------------------------------- |
27 // General helper functions | 27 // General helper functions |
28 | 28 |
| 29 |
| 30 // Same as strcmp, but can handle NULL arguments. |
| 31 inline bool CStringEquals(const char* s1, const char* s2) { |
| 32 return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0); |
| 33 } |
| 34 |
| 35 |
29 // X must be a power of 2. Returns the number of trailing zeros. | 36 // X must be a power of 2. Returns the number of trailing zeros. |
30 inline int WhichPowerOf2(uint32_t x) { | 37 inline int WhichPowerOf2(uint32_t x) { |
31 DCHECK(base::bits::IsPowerOfTwo32(x)); | 38 DCHECK(base::bits::IsPowerOfTwo32(x)); |
32 int bits = 0; | 39 int bits = 0; |
33 #ifdef DEBUG | 40 #ifdef DEBUG |
34 int original_x = x; | 41 int original_x = x; |
35 #endif | 42 #endif |
36 if (x >= 0x10000) { | 43 if (x >= 0x10000) { |
37 bits += 16; | 44 bits += 16; |
38 x >>= 16; | 45 x >>= 16; |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 // Takes the address of the limit variable in order to find out where | 1461 // Takes the address of the limit variable in order to find out where |
1455 // the top of stack is right now. | 1462 // the top of stack is right now. |
1456 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); | 1463 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); |
1457 return limit; | 1464 return limit; |
1458 } | 1465 } |
1459 | 1466 |
1460 } // namespace internal | 1467 } // namespace internal |
1461 } // namespace v8 | 1468 } // namespace v8 |
1462 | 1469 |
1463 #endif // V8_UTILS_H_ | 1470 #endif // V8_UTILS_H_ |
OLD | NEW |