mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-09 07:22:11 +00:00
ICU-5745 Improve performance of translit/TransliteratorTest/TestInstantiation
X-SVN-Rev: 21757
This commit is contained in:
parent
d6824666a4
commit
c3f935855f
4 changed files with 21 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2003-2006, International Business Machines
|
||||
* Copyright (c) 2003-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
|
@ -14,6 +14,9 @@
|
|||
#include "unicode/symtable.h"
|
||||
#include "util.h"
|
||||
|
||||
/* \U87654321 + 2 */
|
||||
#define MAX_U_NOTATION_LEN 12
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
RuleCharacterIterator::RuleCharacterIterator(const UnicodeString& theText, const SymbolTable* theSym,
|
||||
|
@ -66,9 +69,9 @@ UChar32 RuleCharacterIterator::next(int32_t options, UBool& isEscaped, UErrorCod
|
|||
}
|
||||
|
||||
if (c == 0x5C /*'\\'*/ && (options & PARSE_ESCAPES) != 0) {
|
||||
UnicodeString s;
|
||||
UnicodeString tempEscape;
|
||||
int32_t offset = 0;
|
||||
c = lookahead(s).unescapeAt(offset);
|
||||
c = lookahead(tempEscape, MAX_U_NOTATION_LEN).unescapeAt(offset);
|
||||
jumpahead(offset);
|
||||
isEscaped = TRUE;
|
||||
if (c < 0) {
|
||||
|
@ -105,11 +108,14 @@ void RuleCharacterIterator::skipIgnored(int32_t options) {
|
|||
}
|
||||
}
|
||||
|
||||
UnicodeString& RuleCharacterIterator::lookahead(UnicodeString& result) const {
|
||||
UnicodeString& RuleCharacterIterator::lookahead(UnicodeString& result, int32_t maxLookAhead) const {
|
||||
if (maxLookAhead < 0) {
|
||||
maxLookAhead = 0x7FFFFFFF;
|
||||
}
|
||||
if (buf != 0) {
|
||||
buf->extract(bufPos, 0x7FFFFFFF, result);
|
||||
buf->extract(bufPos, maxLookAhead, result);
|
||||
} else {
|
||||
text.extract(pos.getIndex(), 0x7FFFFFFF, result);
|
||||
text.extract(pos.getIndex(), maxLookAhead, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2003-2006, International Business Machines
|
||||
* Copyright (c) 2003-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
|
@ -186,9 +186,10 @@ public:
|
|||
* resynchronize the iterator.
|
||||
* @param result a string to receive the characters to be returned
|
||||
* by future calls to next()
|
||||
* @param maxLookAhead The maximum to copy into the result.
|
||||
* @return a reference to result
|
||||
*/
|
||||
UnicodeString& lookahead(UnicodeString& result) const;
|
||||
UnicodeString& lookahead(UnicodeString& result, int32_t maxLookAhead = -1) const;
|
||||
|
||||
/**
|
||||
* Advances the position by the given number of 16-bit code units.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 1999-2006, International Business Machines
|
||||
* Copyright (C) 1999-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Date Name Description
|
||||
|
@ -502,7 +502,8 @@ UBool UnicodeSet::matchesIndexValue(uint8_t v) const {
|
|||
* time zone month containment logic.)
|
||||
*/
|
||||
int32_t i;
|
||||
for (i=0; i<getRangeCount(); ++i) {
|
||||
int32_t rangeCount=getRangeCount();
|
||||
for (i=0; i<rangeCount; ++i) {
|
||||
UChar32 low = getRangeStart(i);
|
||||
UChar32 high = getRangeEnd(i);
|
||||
if ((low & ~0xFF) == (high & ~0xFF)) {
|
||||
|
|
|
@ -292,6 +292,7 @@ UBool TransliterationRule::masks(const TransliterationRule& r2) const {
|
|||
int32_t left2 = r2.anteContextLength;
|
||||
int32_t right = len - left;
|
||||
int32_t right2 = r2.pattern.length() - left2;
|
||||
int32_t cachedCompare = r2.pattern.compare(left2 - left, len, pattern);
|
||||
|
||||
// TODO Clean this up -- some logic might be combinable with the
|
||||
// next statement.
|
||||
|
@ -299,7 +300,7 @@ UBool TransliterationRule::masks(const TransliterationRule& r2) const {
|
|||
// Test for anchor masking
|
||||
if (left == left2 && right == right2 &&
|
||||
keyLength <= r2.keyLength &&
|
||||
0 == r2.pattern.compare(0, len, pattern)) {
|
||||
0 == cachedCompare) {
|
||||
// The following boolean logic implements the table above
|
||||
return (flags == r2.flags) ||
|
||||
(!(flags & ANCHOR_START) && !(flags & ANCHOR_END)) ||
|
||||
|
@ -309,7 +310,7 @@ UBool TransliterationRule::masks(const TransliterationRule& r2) const {
|
|||
return left <= left2 &&
|
||||
(right < right2 ||
|
||||
(right == right2 && keyLength <= r2.keyLength)) &&
|
||||
0 == r2.pattern.compare(left2 - left, len, pattern);
|
||||
(0 == cachedCompare);
|
||||
}
|
||||
|
||||
static inline int32_t posBefore(const Replaceable& str, int32_t pos) {
|
||||
|
|
Loading…
Add table
Reference in a new issue