OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_UNIBROW_H_ | 5 #ifndef RUNTIME_VM_UNIBROW_H_ |
6 #define RUNTIME_VM_UNIBROW_H_ | 6 #define RUNTIME_VM_UNIBROW_H_ |
7 | 7 |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
11 | 11 |
12 /** | 12 /** |
13 * \file | 13 * \file |
14 * Definitions and convenience functions for working with unicode. | 14 * Definitions and convenience functions for working with unicode. |
15 */ | 15 */ |
16 | 16 |
17 namespace unibrow { | 17 namespace unibrow { |
18 | 18 |
19 // A cache used in case conversion. It caches the value for characters | 19 // A cache used in case conversion. It caches the value for characters |
20 // that either have no mapping or map to a single character independent | 20 // that either have no mapping or map to a single character independent |
21 // of context. Characters that map to more than one character or that | 21 // of context. Characters that map to more than one character or that |
22 // map differently depending on context are always looked up. | 22 // map differently depending on context are always looked up. |
23 template <class T, intptr_t size = 256> | 23 template <class T, intptr_t size = 256> |
24 class Mapping { | 24 class Mapping { |
25 public: | 25 public: |
26 inline Mapping() { } | 26 inline Mapping() {} |
27 inline intptr_t get(int32_t c, int32_t n, int32_t* result); | 27 inline intptr_t get(int32_t c, int32_t n, int32_t* result); |
| 28 |
28 private: | 29 private: |
29 friend class Test; | 30 friend class Test; |
30 intptr_t CalculateValue(int32_t c, int32_t n, int32_t* result); | 31 intptr_t CalculateValue(int32_t c, int32_t n, int32_t* result); |
31 struct CacheEntry { | 32 struct CacheEntry { |
32 inline CacheEntry() : code_point_(kNoChar), offset_(0) { } | 33 inline CacheEntry() : code_point_(kNoChar), offset_(0) {} |
33 inline CacheEntry(int32_t code_point, signed offset) | 34 inline CacheEntry(int32_t code_point, signed offset) |
34 : code_point_(code_point), | 35 : code_point_(code_point), offset_(offset) {} |
35 offset_(offset) { } | |
36 int32_t code_point_; | 36 int32_t code_point_; |
37 signed offset_; | 37 signed offset_; |
38 static const intptr_t kNoChar = (1 << 21) - 1; | 38 static const intptr_t kNoChar = (1 << 21) - 1; |
39 }; | 39 }; |
40 static const intptr_t kSize = size; | 40 static const intptr_t kSize = size; |
41 static const intptr_t kMask = kSize - 1; | 41 static const intptr_t kMask = kSize - 1; |
42 CacheEntry entries_[kSize]; | 42 CacheEntry entries_[kSize]; |
43 }; | 43 }; |
44 | 44 |
45 struct Letter { | 45 struct Letter { |
(...skipping 17 matching lines...) Expand all Loading... |
63 static const intptr_t kMaxWidth = 1; | 63 static const intptr_t kMaxWidth = 1; |
64 static intptr_t Convert(int32_t c, | 64 static intptr_t Convert(int32_t c, |
65 int32_t n, | 65 int32_t n, |
66 int32_t* result, | 66 int32_t* result, |
67 bool* allow_caching_ptr); | 67 bool* allow_caching_ptr); |
68 }; | 68 }; |
69 | 69 |
70 } // namespace unibrow | 70 } // namespace unibrow |
71 | 71 |
72 #endif // RUNTIME_VM_UNIBROW_H_ | 72 #endif // RUNTIME_VM_UNIBROW_H_ |
OLD | NEW |