OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef VM_UNIBROW_INL_H_ |
| 6 #define VM_UNIBROW_INL_H_ |
| 7 |
| 8 #include "vm/unibrow.h" |
| 9 |
| 10 // SNIP |
| 11 |
| 12 namespace unibrow { |
| 13 |
| 14 // SNIP |
| 15 |
| 16 template <class T, int s> int Mapping<T, s>::get(uchar c, uchar n, |
| 17 uchar* result) { |
| 18 CacheEntry entry = entries_[c & kMask]; |
| 19 if (entry.code_point_ == c) { |
| 20 if (entry.offset_ == 0) { |
| 21 return 0; |
| 22 } else { |
| 23 result[0] = c + entry.offset_; |
| 24 return 1; |
| 25 } |
| 26 } else { |
| 27 return CalculateValue(c, n, result); |
| 28 } |
| 29 } |
| 30 |
| 31 template <class T, int s> int Mapping<T, s>::CalculateValue(uchar c, uchar n, |
| 32 uchar* result) { |
| 33 bool allow_caching = true; |
| 34 int length = T::Convert(c, n, result, &allow_caching); |
| 35 if (allow_caching) { |
| 36 if (length == 1) { |
| 37 entries_[c & kMask] = CacheEntry(c, result[0] - c); |
| 38 return 1; |
| 39 } else { |
| 40 entries_[c & kMask] = CacheEntry(c, 0); |
| 41 return 0; |
| 42 } |
| 43 } else { |
| 44 return length; |
| 45 } |
| 46 } |
| 47 |
| 48 // SNIP |
| 49 |
| 50 } // namespace unibrow |
| 51 |
| 52 #endif // VM_UNIBROW_INL_H_ |
OLD | NEW |