mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 20:51:50 +00:00
8e807c8550
BUG=http://dartbug.com/19090 R=fschneider@google.com Committed: https://code.google.com/p/dart/source/detail?r=41949 Review URL: https://codereview.chromium.org//744853003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@41983 260f80e4-7a28-3924-810f-c04153c831b5
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef VM_UNIBROW_INL_H_
|
|
#define VM_UNIBROW_INL_H_
|
|
|
|
#include "vm/unibrow.h"
|
|
|
|
#include "platform/assert.h"
|
|
|
|
namespace unibrow {
|
|
|
|
template <class T, intptr_t s> intptr_t Mapping<T, s>::get(
|
|
int32_t c, int32_t n, int32_t* result) {
|
|
CacheEntry entry = entries_[c & kMask];
|
|
if (entry.code_point_ == c) {
|
|
if (entry.offset_ == 0) {
|
|
return 0;
|
|
} else {
|
|
result[0] = c + entry.offset_;
|
|
return 1;
|
|
}
|
|
} else {
|
|
return CalculateValue(c, n, result);
|
|
}
|
|
}
|
|
|
|
template <class T, intptr_t s> intptr_t Mapping<T, s>::CalculateValue(
|
|
int32_t c, int32_t n, int32_t* result) {
|
|
bool allow_caching = true;
|
|
intptr_t length = T::Convert(c, n, result, &allow_caching);
|
|
if (allow_caching) {
|
|
if (length == 1) {
|
|
entries_[c & kMask] = CacheEntry(c, result[0] - c);
|
|
return 1;
|
|
} else {
|
|
entries_[c & kMask] = CacheEntry(c, 0);
|
|
return 0;
|
|
}
|
|
} else {
|
|
return length;
|
|
}
|
|
}
|
|
|
|
} // namespace unibrow
|
|
|
|
#endif // VM_UNIBROW_INL_H_
|