ICU-1087 Speed up the TimeZone construction with a proper constructor, and make getGMT() public
X-SVN-Rev: 5470
This commit is contained in:
parent
051f850dcf
commit
e3df919a30
@ -39,7 +39,8 @@ const int8_t SimpleTimeZone::staticMonthLength[] = {31,28,31,30,31,30,31,31,30,3
|
||||
|
||||
|
||||
SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID)
|
||||
: startMonth(0),
|
||||
: TimeZone(ID),
|
||||
startMonth(0),
|
||||
startDay(0),
|
||||
startDayOfWeek(0),
|
||||
startTime(0),
|
||||
@ -56,7 +57,6 @@ SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID)
|
||||
endMode(DOM_MODE),
|
||||
dstSavings(U_MILLIS_PER_HOUR)
|
||||
{
|
||||
setID(ID);
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
@ -66,8 +66,10 @@ SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
|
||||
int8_t savingsEndMonth, int8_t savingsEndDay,
|
||||
int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
|
||||
UErrorCode& status) {
|
||||
construct(rawOffsetGMT, ID,
|
||||
UErrorCode& status)
|
||||
: TimeZone(ID)
|
||||
{
|
||||
construct(rawOffsetGMT,
|
||||
savingsStartMonth, savingsStartDay, savingsStartDayOfWeek,
|
||||
savingsStartTime, WALL_TIME,
|
||||
savingsEndMonth, savingsEndDay, savingsEndDayOfWeek,
|
||||
@ -82,8 +84,10 @@ SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
|
||||
int8_t savingsEndMonth, int8_t savingsEndDay,
|
||||
int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
|
||||
int32_t savingsDST, UErrorCode& status) {
|
||||
construct(rawOffsetGMT, ID,
|
||||
int32_t savingsDST, UErrorCode& status)
|
||||
: TimeZone(ID)
|
||||
{
|
||||
construct(rawOffsetGMT,
|
||||
savingsStartMonth, savingsStartDay, savingsStartDayOfWeek,
|
||||
savingsStartTime, WALL_TIME,
|
||||
savingsEndMonth, savingsEndDay, savingsEndDayOfWeek,
|
||||
@ -100,8 +104,10 @@ SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
int8_t savingsEndMonth, int8_t savingsEndDay,
|
||||
int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
|
||||
TimeMode savingsEndTimeMode,
|
||||
int32_t savingsDST, UErrorCode& status) {
|
||||
construct(rawOffsetGMT, ID,
|
||||
int32_t savingsDST, UErrorCode& status)
|
||||
: TimeZone(ID)
|
||||
{
|
||||
construct(rawOffsetGMT,
|
||||
savingsStartMonth, savingsStartDay, savingsStartDayOfWeek,
|
||||
savingsStartTime, savingsStartTimeMode,
|
||||
savingsEndMonth, savingsEndDay, savingsEndDayOfWeek,
|
||||
@ -113,9 +119,11 @@ SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
* Construct from memory-mapped data. For private use by TimeZone.
|
||||
*/
|
||||
SimpleTimeZone::SimpleTimeZone(const StandardZone& stdZone,
|
||||
const UnicodeString& id) {
|
||||
const UnicodeString& ID)
|
||||
: TimeZone(ID)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
construct(stdZone.gmtOffset, id,
|
||||
construct(stdZone.gmtOffset,
|
||||
0, 0, 0, 0, WALL_TIME,
|
||||
0, 0, 0, 0, WALL_TIME,
|
||||
0, status);
|
||||
@ -125,9 +133,11 @@ SimpleTimeZone::SimpleTimeZone(const StandardZone& stdZone,
|
||||
* Construct from memory-mapped data. For private use by TimeZone.
|
||||
*/
|
||||
SimpleTimeZone::SimpleTimeZone(const DSTZone& dstZone,
|
||||
const UnicodeString& id) {
|
||||
const UnicodeString& ID)
|
||||
: TimeZone(ID)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
construct(dstZone.gmtOffset, id,
|
||||
construct(dstZone.gmtOffset,
|
||||
dstZone.onsetRule.month, dstZone.onsetRule.dowim,
|
||||
dstZone.onsetRule.dow,
|
||||
dstZone.onsetRule.time * (int32_t)60000,
|
||||
@ -142,7 +152,7 @@ SimpleTimeZone::SimpleTimeZone(const DSTZone& dstZone,
|
||||
/**
|
||||
* Internal construction method.
|
||||
*/
|
||||
void SimpleTimeZone::construct(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
void SimpleTimeZone::construct(int32_t rawOffsetGMT,
|
||||
int8_t savingsStartMonth,
|
||||
int8_t savingsStartDay,
|
||||
int8_t savingsStartDayOfWeek,
|
||||
@ -154,7 +164,8 @@ void SimpleTimeZone::construct(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
int32_t savingsEndTime,
|
||||
TimeMode savingsEndTimeMode,
|
||||
int32_t savingsDST,
|
||||
UErrorCode& status) {
|
||||
UErrorCode& status)
|
||||
{
|
||||
this->rawOffset = rawOffsetGMT;
|
||||
this->startMonth = savingsStartMonth;
|
||||
this->startDay = savingsStartDay;
|
||||
@ -167,8 +178,6 @@ void SimpleTimeZone::construct(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
this->endTime = savingsEndTime;
|
||||
this->endTimeMode = savingsEndTimeMode;
|
||||
this->dstSavings = savingsDST;
|
||||
|
||||
setID(ID);
|
||||
this->startYear = 0;
|
||||
this->startMode = DOM_MODE;
|
||||
this->endMode = DOM_MODE;
|
||||
@ -190,6 +199,7 @@ SimpleTimeZone::~SimpleTimeZone()
|
||||
|
||||
// Called by TimeZone::createDefault(), then clone() inside a Mutex - be careful.
|
||||
SimpleTimeZone::SimpleTimeZone(const SimpleTimeZone &source)
|
||||
: TimeZone(source)
|
||||
{
|
||||
*this = source;
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ static const UChar CUSTOM_ID[] =
|
||||
0x43, 0x75, 0x73, 0x74, 0x6F, 0x6D, 0x00 /* "Custom" */
|
||||
};
|
||||
|
||||
#ifdef ICU_TIMEZONE_USE_DEPRECATES
|
||||
const TimeZone* TimeZone::GMT = getGMT();
|
||||
#endif
|
||||
|
||||
// See header file for documentation of the following
|
||||
static const TZHeader * DATA = 0;
|
||||
@ -75,7 +77,7 @@ static const TZEquivalencyGroup* lookupEquivalencyGroup(const UnicodeString& id)
|
||||
const TimeZone*
|
||||
TimeZone::getGMT(void)
|
||||
{
|
||||
static const SimpleTimeZone SIMPLE_GMT(0, GMT_ID);
|
||||
static const SimpleTimeZone SIMPLE_GMT(0, UnicodeString(GMT_ID, GMT_ID_LENGTH));
|
||||
return &SIMPLE_GMT;
|
||||
}
|
||||
|
||||
@ -168,6 +170,13 @@ TimeZone::TimeZone()
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
TimeZone::TimeZone(const UnicodeString &id)
|
||||
: fID(id)
|
||||
{
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
TimeZone::~TimeZone()
|
||||
{
|
||||
}
|
||||
@ -218,7 +227,7 @@ TimeZone::createTimeZone(const UnicodeString& ID)
|
||||
result = createCustomTimeZone(ID);
|
||||
}
|
||||
if (result == 0) {
|
||||
result = GMT->clone();
|
||||
result = getGMT()->clone();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -351,7 +360,7 @@ TimeZone::initDefault()
|
||||
// can only happen if the raw offset returned by
|
||||
// uprv_timezone() does not correspond to any system zone.
|
||||
if (fgDefaultZone == 0) {
|
||||
fgDefaultZone = GMT->clone();
|
||||
fgDefaultZone = getGMT()->clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -378,7 +387,7 @@ TimeZone::adoptDefault(TimeZone* zone)
|
||||
|
||||
if (fgDefaultZone != NULL) {
|
||||
delete fgDefaultZone;
|
||||
}
|
||||
}
|
||||
|
||||
fgDefaultZone = zone;
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ private:
|
||||
/**
|
||||
* Internal construction method.
|
||||
*/
|
||||
void construct(int32_t rawOffsetGMT, const UnicodeString& ID,
|
||||
void construct(int32_t rawOffsetGMT,
|
||||
int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
|
||||
int32_t startTime, TimeMode startTimeMode,
|
||||
int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
|
||||
|
@ -10,15 +10,16 @@
|
||||
* 04/21/97 aliu Overhauled header.
|
||||
* 07/09/97 helena Changed createInstance to createDefault.
|
||||
* 08/06/97 aliu Removed dependency on internal header for Hashtable.
|
||||
* 08/10/98 stephen Changed getDisplayName() API conventions to match
|
||||
* 08/19/98 stephen Changed createTimeZone() to never return 0
|
||||
* 09/02/98 stephen Sync to JDK 1.2 8/31
|
||||
* - Added getOffset(... monthlen ...)
|
||||
* - Added hasSameRules()
|
||||
* 09/15/98 stephen Added getStaticClassID
|
||||
* 12/03/99 aliu Moved data out of static table into icudata.dll.
|
||||
* 08/10/98 stephen Changed getDisplayName() API conventions to match
|
||||
* 08/19/98 stephen Changed createTimeZone() to never return 0
|
||||
* 09/02/98 stephen Sync to JDK 1.2 8/31
|
||||
* - Added getOffset(... monthlen ...)
|
||||
* - Added hasSameRules()
|
||||
* 09/15/98 stephen Added getStaticClassID
|
||||
* 12/03/99 aliu Moved data out of static table into icudata.dll.
|
||||
* Hashtable replaced by new static data structures.
|
||||
* 12/14/99 aliu Made GMT public.
|
||||
* 12/14/99 aliu Made GMT public.
|
||||
* 08/15/01 grhoten Made GMT private and added the getGMT() function
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
@ -65,8 +66,6 @@
|
||||
* when you specify a custom time zone ID does not include
|
||||
* daylight savings time.
|
||||
*
|
||||
|
||||
|
||||
* TimeZone is an abstract class representing a time zone. A TimeZone is needed for
|
||||
* Calendar to produce local time for a particular time zone. A TimeZone comprises
|
||||
* three basic pieces of information:<ul>
|
||||
@ -108,11 +107,21 @@ public:
|
||||
*/
|
||||
virtual ~TimeZone();
|
||||
|
||||
#ifdef ICU_TIMEZONE_USE_DEPRECATES
|
||||
/**
|
||||
* The GMT zone has a raw offset of zero and does not use daylight
|
||||
* savings time.
|
||||
* @deprecated This variable can be improperly intialized when used during
|
||||
* the static initialization process. Use getGMT() instead.
|
||||
*/
|
||||
static const TimeZone* GMT;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The GMT time zone has a raw offset of zero and does not use daylight
|
||||
* savings time. This is a commonly used time zone.
|
||||
*/
|
||||
static const TimeZone* getGMT(void);
|
||||
|
||||
/**
|
||||
* Creates a <code>TimeZone</code> for the given ID.
|
||||
@ -503,6 +512,12 @@ protected:
|
||||
*/
|
||||
TimeZone();
|
||||
|
||||
/**
|
||||
* Construct a timezone with a given ID.
|
||||
* @stable
|
||||
*/
|
||||
TimeZone(const UnicodeString &id);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @stable
|
||||
@ -529,11 +544,6 @@ private:
|
||||
*/
|
||||
static void initDefault(void);
|
||||
|
||||
/**
|
||||
* Get the the GMT TimeZone.
|
||||
*/
|
||||
static const TimeZone *getGMT(void);
|
||||
|
||||
// See source file for documentation
|
||||
static TimeZone* createSystemTimeZone(const UnicodeString& name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user