Speed up timezone detection

This commit is contained in:
Alexey Andreev 2015-05-18 21:10:08 +03:00
parent b9ed20ddb0
commit 33c32bc035
5 changed files with 27 additions and 14 deletions

View File

@ -131,7 +131,7 @@ public class DateTimeZoneProvider {
if (scoreTable.size() == 1 || scoreTable.get(0).tz.previousTransition(time) == time) {
return scoreTable.get(0).tz;
} else if (scoreTable.size() > 1 && scoreTable.get(0).value + 48 * 7 < scoreTable.get(1).value) {
} else if (scoreTable.size() > 1 && scoreTable.get(0).value + 48 * 60 < scoreTable.get(1).value) {
return scoreTable.get(0).tz;
}

View File

@ -146,6 +146,10 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl
"DAY_OF_MONTH=", "DAY_OF_YEAR=", "DAY_OF_WEEK=", "DAY_OF_WEEK_IN_MONTH=", "AM_PM=", "HOUR=", "HOUR_OF_DAY",
"MINUTE=", "SECOND=", "MILLISECOND=", "ZONE_OFFSET=", "DST_OFFSET=" };
private static int firstDayOfWeekCache = -1;
private static int minimalDaysInFirstWeekCache = -1;
private static TLocale cacheFor;
protected TCalendar() {
this(TLocale.getDefault());
}
@ -157,6 +161,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl
setLenient(true);
setFirstDayOfWeek(resolveFirstDayOfWeek(locale));
setMinimalDaysInFirstWeek(resolveMinimalDaysInFirstWeek(locale));
cacheFor = locale;
}
private static String resolveCountry(TLocale locale) {
@ -170,15 +175,24 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl
}
private static int resolveFirstDayOfWeek(TLocale locale) {
if (locale == cacheFor && firstDayOfWeekCache >= 0) {
return firstDayOfWeekCache;
}
String country = resolveCountry(locale);
ResourceMap<IntResource> dayMap = CLDRHelper.getFirstDayOfWeek();
return dayMap.has(country) ? dayMap.get(country).getValue() : dayMap.get("001").getValue();
firstDayOfWeekCache = dayMap.has(country) ? dayMap.get(country).getValue() : dayMap.get("001").getValue();
return firstDayOfWeekCache;
}
private static int resolveMinimalDaysInFirstWeek(TLocale locale) {
if (locale == cacheFor && minimalDaysInFirstWeekCache >= 0) {
return minimalDaysInFirstWeekCache;
}
String country = resolveCountry(locale);
ResourceMap<IntResource> dayMap = CLDRHelper.getMinimalDaysInFirstWeek();
return dayMap.has(country) ? dayMap.get(country).getValue() : dayMap.get("001").getValue();
minimalDaysInFirstWeekCache = dayMap.has(country) ? dayMap.get(country).getValue() :
dayMap.get("001").getValue();
return minimalDaysInFirstWeekCache;
}
abstract public void add(int field, int value);

View File

@ -598,6 +598,7 @@ Long.prototype.toString = function() {
return positive ? result : "-" + result;
}
var Long_ZERO = new Long(0, 0);
var Long_MAX_NORMAL = 1 << 18;
function Long_fromInt(val) {
return val >= 0 ? new Long(val, 0) : new Long(val, -1);
}
@ -619,6 +620,8 @@ function Long_toNumber(val) {
function Long_add(a, b) {
if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) {
return Long_fromNumber(a.lo + b.lo);
} else if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) + Long_toNumber(b));
}
var a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16;
@ -729,13 +732,13 @@ function Long_mul(a, b) {
return positive ? result : Long_neg(result);
}
function Long_div(a, b) {
if (a.hi === 0 && b.hi === 0) {
if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b));
}
return Long_divRem(a, b)[0];
}
function Long_rem(a, b) {
if (a.hi === 0 && b.hi === 0) {
if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) % Long_toNumber(b));
}
return Long_divRem(a, b)[1];

View File

@ -22,12 +22,12 @@ import org.teavm.jso.JSObject;
* @author Alexey Andreev
*/
public interface CanvasGradient extends JSObject {
/**
* The CanvasGradient.addColorStop() method adds a new stop, defined by an
* offset and a color, to the gradient. If the offset is not between 0 and 1,
* an INDEX_SIZE_ERR is raised, if the color can't be parsed as a CSS color,
* a SYNTAX_ERR is raised.
* <p>The CanvasGradient.addColorStop() method adds a new stop, defined by an
* offset and a color, to the gradient. If the offset is not between 0 and 1,
* an INDEX_SIZE_ERR is raised, if the color can't be parsed as a CSS color,
* a SYNTAX_ERR is raised.</p>
*
* @param offset Offset between 0 and 1
* @param color A CSS parseable color.
*/

View File

@ -24,7 +24,6 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.junit.Test;
import org.teavm.classlib.impl.tz.DateTimeZoneProvider;
/**
*
@ -36,9 +35,6 @@ public class TimeZoneTest {
@Test
public void test_getDefault() {
assertNotSame("returns identical", TimeZone.getDefault(), TimeZone.getDefault());
for (int i = 0; i < 30; ++i) {
DateTimeZoneProvider.detectTimezone();
}
}
@Test