Skip to content

Commit

Permalink
CLDR-17342 speedup CoverageLevel2 construction
Browse files Browse the repository at this point in the history
- use CLDRLocale instead of LanguageTagParser
- about a 3x speedup for construct + 1 lookup
  • Loading branch information
srl295 committed Feb 12, 2024
1 parent 9d96f34 commit 8348e75
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.unicode.cldr.util.CLDRLocale;
import org.unicode.cldr.util.CLDRPaths;
import org.unicode.cldr.util.CldrUtility.VariableReplacer;
import org.unicode.cldr.util.LanguageTagParser;
import org.unicode.cldr.util.Level;
import org.unicode.cldr.util.PathHeader;
import org.unicode.cldr.util.PatternCache;
Expand Down Expand Up @@ -153,13 +152,13 @@ public boolean equals(Object obj) {
}

private CoverageLevel2(SupplementalDataInfo sdi, String locale) {
myInfo.targetLanguage = new LanguageTagParser().set(locale).getLanguage();
myInfo.targetLanguage = CLDRLocale.getInstance(locale).getLanguage();
myInfo.cvi = sdi.getCoverageVariableInfo(myInfo.targetLanguage);
lookup = sdi.getCoverageLookup();
}

private CoverageLevel2(SupplementalDataInfo sdi, String locale, String ruleFile) {
myInfo.targetLanguage = new LanguageTagParser().set(locale).getLanguage();
myInfo.targetLanguage = CLDRLocale.getInstance(locale).getLanguage();
myInfo.cvi = sdi.getCoverageVariableInfo(myInfo.targetLanguage);
RawCoverageFile rcf = new RawCoverageFile();
lookup = rcf.load(ruleFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.unicode.cldr.util;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.unicode.cldr.test.CoverageLevel2;

public class TestCoverageLevel2 {

final int ITERATIONS = 100000; // keep this low for normal testing

private static SupplementalDataInfo sdi;

@BeforeAll
private static void setup() {
sdi = CLDRConfig.getInstance().getSupplementalDataInfo();
CoverageLevel2 c = CoverageLevel2.getInstance(sdi, "fr_CA");
}

@Test
public void TestCoveragePerf() {
for (int i = 0; i < ITERATIONS; i++) {
CoverageLevel2 c = CoverageLevel2.getInstance(sdi, "fr_CA");
assertEquals(
Level.MODERATE,
c.getLevel(
"//ldml/characters/parseLenients[@scope=\"number\"][@level=\"lenient\"]/parseLenient[@sample=\",\"]"));
}
}
}

0 comments on commit 8348e75

Please sign in to comment.