ICU-2729 Make it easier to hide gStaticSets in the future,
X-SVN-Rev: 12134
This commit is contained in:
parent
8d76362fd2
commit
b57ac91414
@ -89,8 +89,8 @@ RegexCompile::~RegexCompile() {
|
||||
//
|
||||
//----------------------------------------------------------------------------------------
|
||||
void RegexCompile::cleanup() {
|
||||
delete RegexPattern::gStaticSets;
|
||||
RegexPattern::gStaticSets = NULL;
|
||||
delete RegexStaticSets::gStaticSets;
|
||||
RegexStaticSets::gStaticSets = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -122,8 +122,8 @@ void RegexCompile::compile(
|
||||
// Prepare the RegexPattern object to receive the compiled pattern.
|
||||
// TODO: remove per-instance field, and just use globals directly. (But check perf)
|
||||
fRXPat->fPattern = pat;
|
||||
fRXPat->fStaticSets = RegexPattern::gStaticSets->fPropSets;
|
||||
fRXPat->fStaticSets8 = RegexPattern::gStaticSets->fPropSets8;
|
||||
fRXPat->fStaticSets = RegexStaticSets::gStaticSets->fPropSets;
|
||||
fRXPat->fStaticSets8 = RegexStaticSets::gStaticSets->fPropSets8;
|
||||
|
||||
|
||||
// Initialize the pattern scanning state machine
|
||||
@ -186,7 +186,7 @@ void RegexCompile::compile(
|
||||
if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class &&
|
||||
fC.fQuoted == FALSE && // char is not escaped &&
|
||||
fC.fChar != (UChar32)-1) { // char is not EOF
|
||||
UnicodeSet *uniset = RegexPattern::gStaticSets->fRuleSets[tableEl->fCharClass-128];
|
||||
UnicodeSet *uniset = RegexStaticSets::gStaticSets->fRuleSets[tableEl->fCharClass-128];
|
||||
if (uniset->contains(fC.fChar)) {
|
||||
// Table row specified a character class, or set of characters,
|
||||
// and the current char matches it.
|
||||
@ -1186,7 +1186,7 @@ UBool RegexCompile::doParseActions(EParseAction action)
|
||||
break;
|
||||
}
|
||||
c = peekCharLL();
|
||||
if (RegexPattern::gStaticSets->fRuleDigits->contains(c) == FALSE) {
|
||||
if (RegexStaticSets::gStaticSets->fRuleDigits->contains(c) == FALSE) {
|
||||
break;
|
||||
}
|
||||
nextCharLL();
|
||||
@ -3377,7 +3377,7 @@ void RegexCompile::nextChar(RegexPatternChar &c) {
|
||||
int32_t startX = fNextIndex; // start and end positions of the
|
||||
int32_t endX = fNextIndex; // sequence following the '\'
|
||||
if (c.fChar == chBackSlash) {
|
||||
if (RegexPattern::gStaticSets->fUnescapeCharSet->contains(peekCharLL())) {
|
||||
if (RegexStaticSets::gStaticSets->fUnescapeCharSet->contains(peekCharLL())) {
|
||||
//
|
||||
// A '\' sequence that is handled by ICU's standard unescapeAt function.
|
||||
// Includes \uxxxx, \n, \r, many others.
|
||||
|
@ -147,7 +147,7 @@ static const UChar gIsWordPattern[] = {
|
||||
// l a b l e _ T y p e = L V T } ]
|
||||
0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x56, 0x54, 0x7d, 0x5d, 0};
|
||||
|
||||
|
||||
RegexStaticSets *RegexStaticSets::gStaticSets = NULL;
|
||||
|
||||
RegexStaticSets::RegexStaticSets(UErrorCode *status) {
|
||||
// First zero out everything
|
||||
@ -229,9 +229,9 @@ RegexStaticSets::~RegexStaticSets() {
|
||||
};
|
||||
|
||||
|
||||
void RegexStaticSets::initGlobals(RegexStaticSets **globals, UErrorCode *status) {
|
||||
void RegexStaticSets::initGlobals(UErrorCode *status) {
|
||||
umtx_lock(NULL);
|
||||
RegexStaticSets *p = *globals;
|
||||
RegexStaticSets *p = gStaticSets;
|
||||
umtx_unlock(NULL);
|
||||
if (p == NULL) {
|
||||
p = new RegexStaticSets(status);
|
||||
@ -239,12 +239,14 @@ void RegexStaticSets::initGlobals(RegexStaticSets **globals, UErrorCode *status)
|
||||
return;
|
||||
}
|
||||
umtx_lock(NULL);
|
||||
if (*globals == NULL) {
|
||||
*globals = p;
|
||||
if (gStaticSets == NULL) {
|
||||
gStaticSets = p;
|
||||
p = NULL;
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
delete p;
|
||||
if (p) {
|
||||
delete p;
|
||||
}
|
||||
ucln_i18n_registerCleanup();
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,12 @@ class UnicodeSet;
|
||||
|
||||
class RegexStaticSets {
|
||||
public:
|
||||
static RegexStaticSets *gStaticSets; // Ptr to all lazily initialized constant
|
||||
// shared sets.
|
||||
|
||||
RegexStaticSets(UErrorCode *status);
|
||||
~RegexStaticSets();
|
||||
static void initGlobals(RegexStaticSets **p, UErrorCode *status);
|
||||
static void initGlobals(UErrorCode *status);
|
||||
|
||||
UnicodeSet *fPropSets[URX_LAST_SET]; // The sets for common regex items, e.g. \s
|
||||
Regex8BitSet fPropSets8[URX_LAST_SET]; // Fast bitmap sets for latin-1 range for above.
|
||||
|
@ -53,7 +53,7 @@ RegexMatcher::RegexMatcher(const RegexPattern *pat) {
|
||||
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
|
||||
reset(*RegexPattern::gStaticSets->fEmptyString);
|
||||
reset(*RegexStaticSets::gStaticSets->fEmptyString);
|
||||
}
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ RegexMatcher::RegexMatcher(const UnicodeString ®exp,
|
||||
if (fStack == NULL || fData == NULL) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
reset(*RegexPattern::gStaticSets->fEmptyString);
|
||||
reset(*RegexStaticSets::gStaticSets->fEmptyString);
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,13 +27,12 @@ U_NAMESPACE_BEGIN
|
||||
// RegexPattern Default Constructor
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
RegexStaticSets *RegexPattern::gStaticSets = NULL;
|
||||
RegexPattern::RegexPattern() {
|
||||
// Init all of this instances data.
|
||||
init();
|
||||
|
||||
// Lazy init of all shared global sets.
|
||||
RegexStaticSets::initGlobals(&RegexPattern::gStaticSets, &fDeferredStatus);
|
||||
RegexStaticSets::initGlobals(&fDeferredStatus);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user