mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-10 08:54:11 -08:00
Speed up timezone detection
This commit is contained in:
parent
b9ed20ddb0
commit
33c32bc035
|
@ -131,7 +131,7 @@ public class DateTimeZoneProvider {
|
||||||
|
|
||||||
if (scoreTable.size() == 1 || scoreTable.get(0).tz.previousTransition(time) == time) {
|
if (scoreTable.size() == 1 || scoreTable.get(0).tz.previousTransition(time) == time) {
|
||||||
return scoreTable.get(0).tz;
|
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;
|
return scoreTable.get(0).tz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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",
|
"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=" };
|
"MINUTE=", "SECOND=", "MILLISECOND=", "ZONE_OFFSET=", "DST_OFFSET=" };
|
||||||
|
|
||||||
|
private static int firstDayOfWeekCache = -1;
|
||||||
|
private static int minimalDaysInFirstWeekCache = -1;
|
||||||
|
private static TLocale cacheFor;
|
||||||
|
|
||||||
protected TCalendar() {
|
protected TCalendar() {
|
||||||
this(TLocale.getDefault());
|
this(TLocale.getDefault());
|
||||||
}
|
}
|
||||||
|
@ -157,6 +161,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl
|
||||||
setLenient(true);
|
setLenient(true);
|
||||||
setFirstDayOfWeek(resolveFirstDayOfWeek(locale));
|
setFirstDayOfWeek(resolveFirstDayOfWeek(locale));
|
||||||
setMinimalDaysInFirstWeek(resolveMinimalDaysInFirstWeek(locale));
|
setMinimalDaysInFirstWeek(resolveMinimalDaysInFirstWeek(locale));
|
||||||
|
cacheFor = locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String resolveCountry(TLocale 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) {
|
private static int resolveFirstDayOfWeek(TLocale locale) {
|
||||||
|
if (locale == cacheFor && firstDayOfWeekCache >= 0) {
|
||||||
|
return firstDayOfWeekCache;
|
||||||
|
}
|
||||||
String country = resolveCountry(locale);
|
String country = resolveCountry(locale);
|
||||||
ResourceMap<IntResource> dayMap = CLDRHelper.getFirstDayOfWeek();
|
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) {
|
private static int resolveMinimalDaysInFirstWeek(TLocale locale) {
|
||||||
|
if (locale == cacheFor && minimalDaysInFirstWeekCache >= 0) {
|
||||||
|
return minimalDaysInFirstWeekCache;
|
||||||
|
}
|
||||||
String country = resolveCountry(locale);
|
String country = resolveCountry(locale);
|
||||||
ResourceMap<IntResource> dayMap = CLDRHelper.getMinimalDaysInFirstWeek();
|
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);
|
abstract public void add(int field, int value);
|
||||||
|
|
|
@ -598,6 +598,7 @@ Long.prototype.toString = function() {
|
||||||
return positive ? result : "-" + result;
|
return positive ? result : "-" + result;
|
||||||
}
|
}
|
||||||
var Long_ZERO = new Long(0, 0);
|
var Long_ZERO = new Long(0, 0);
|
||||||
|
var Long_MAX_NORMAL = 1 << 18;
|
||||||
function Long_fromInt(val) {
|
function Long_fromInt(val) {
|
||||||
return val >= 0 ? new Long(val, 0) : new Long(val, -1);
|
return val >= 0 ? new Long(val, 0) : new Long(val, -1);
|
||||||
}
|
}
|
||||||
|
@ -619,6 +620,8 @@ function Long_toNumber(val) {
|
||||||
function Long_add(a, b) {
|
function Long_add(a, b) {
|
||||||
if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) {
|
if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) {
|
||||||
return Long_fromNumber(a.lo + b.lo);
|
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_lolo = a.lo & 0xFFFF;
|
||||||
var a_lohi = a.lo >>> 16;
|
var a_lohi = a.lo >>> 16;
|
||||||
|
@ -729,13 +732,13 @@ function Long_mul(a, b) {
|
||||||
return positive ? result : Long_neg(result);
|
return positive ? result : Long_neg(result);
|
||||||
}
|
}
|
||||||
function Long_div(a, b) {
|
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_fromNumber(Long_toNumber(a) / Long_toNumber(b));
|
||||||
}
|
}
|
||||||
return Long_divRem(a, b)[0];
|
return Long_divRem(a, b)[0];
|
||||||
}
|
}
|
||||||
function Long_rem(a, b) {
|
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_fromNumber(Long_toNumber(a) % Long_toNumber(b));
|
||||||
}
|
}
|
||||||
return Long_divRem(a, b)[1];
|
return Long_divRem(a, b)[1];
|
||||||
|
|
|
@ -22,12 +22,12 @@ import org.teavm.jso.JSObject;
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public interface CanvasGradient extends JSObject {
|
public interface CanvasGradient extends JSObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CanvasGradient.addColorStop() method adds a new stop, defined by an
|
* <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,
|
* 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,
|
* an INDEX_SIZE_ERR is raised, if the color can't be parsed as a CSS color,
|
||||||
* a SYNTAX_ERR is raised.
|
* a SYNTAX_ERR is raised.</p>
|
||||||
|
*
|
||||||
* @param offset Offset between 0 and 1
|
* @param offset Offset between 0 and 1
|
||||||
* @param color A CSS parseable color.
|
* @param color A CSS parseable color.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.teavm.classlib.impl.tz.DateTimeZoneProvider;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -36,9 +35,6 @@ public class TimeZoneTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_getDefault() {
|
public void test_getDefault() {
|
||||||
assertNotSame("returns identical", TimeZone.getDefault(), TimeZone.getDefault());
|
assertNotSame("returns identical", TimeZone.getDefault(), TimeZone.getDefault());
|
||||||
for (int i = 0; i < 30; ++i) {
|
|
||||||
DateTimeZoneProvider.detectTimezone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user