diff --git a/lib/Parser/RegexCompileTime.cpp b/lib/Parser/RegexCompileTime.cpp index 7d6ad5d34cc..2b27c0242b9 100644 --- a/lib/Parser/RegexCompileTime.cpp +++ b/lib/Parser/RegexCompileTime.cpp @@ -1173,7 +1173,17 @@ namespace UnifiedRegex { if ((compiler.program->flags & IgnoreCaseRegexFlag) != 0) { - Char equivs[CaseInsensitive::EquivClassSize]; + // To ensure initialization, we first default-initialize the + // whole array with a constant, and then individually set it + // to be just the first character (known to exist). This can + // hopefully be optimized to just initialize to cs[0] by the + // compiler. + Char equivs[CaseInsensitive::EquivClassSize] = { (Char)-1 }; + for (int i = 0; i < CaseInsensitive::EquivClassSize; i++) + { + equivs[i] = cs[0]; + + } bool isNonTrivial = compiler.standardChars->ToEquivs(compiler.program->GetCaseMappingSource(), cs[0], equivs); if (isNonTrivial) { @@ -1279,10 +1289,23 @@ namespace UnifiedRegex { if (isEquivClass) { - Char uniqueEquivs[CaseInsensitive::EquivClassSize]; + // To ensure initialization, we first default-initialize the + // whole array with a constant, and then individually set it + // to be just the first character (known to exist). This can + // hopefully be optimized to just initialize to cs[0] by the + // compiler. + Char uniqueEquivs[CaseInsensitive::EquivClassSize] = { (Char)-1 }; + for (int i = 0; i < CaseInsensitive::EquivClassSize; i++) + { + uniqueEquivs[i] = cs[0]; + } CharCount uniqueEquivCount = FindUniqueEquivs(cs, uniqueEquivs); switch (uniqueEquivCount) { + case 1: + EMIT(compiler, MatchCharInst, uniqueEquivs[0]); + break; + case 2: EMIT(compiler, MatchChar2Inst, uniqueEquivs[0], uniqueEquivs[1]); break; diff --git a/lib/Parser/RegexCompileTime.h b/lib/Parser/RegexCompileTime.h index bbd0d12fc99..2f293bd60c4 100644 --- a/lib/Parser/RegexCompileTime.h +++ b/lib/Parser/RegexCompileTime.h @@ -374,10 +374,8 @@ namespace UnifiedRegex , isEquivClass(false) { cs[0] = c; -#if DBG for (int i = 1; i < CaseInsensitive::EquivClassSize; i++) - cs[i] = (Char)-1; -#endif + cs[i] = c; } NODE_DECL