Various timezone updates.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14606 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-09-30 16:54:29 +00:00
parent bf19246ca2
commit 30e7e62540
8 changed files with 571 additions and 417 deletions

View file

@ -1,6 +1,9 @@
2002-09-30 Richard Frith-Macdonald <rfm@gnu.org>
* NSTimeZones/NSTimeZones.tar: Updated to latest information.
* Source/NSCalendarDate.m: Tidy up a little.
* Source/NSTimeZone.m: Rewrite main timezone code for performance -
Roughly doubles speed of most NSCalendarDate stuff.
2002-09-29 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -58,6 +58,8 @@
#define GREGORIAN_REFERENCE 730486
static NSTimeZone *localTZ = nil;
static inline int
lastDayOfGregorianMonth(int month, int year)
{
@ -196,6 +198,7 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
if (self == [NSCalendarDate class])
{
[self setVersion: 1];
localTZ = RETAIN([NSTimeZone localTimeZone]);
behavior_class_add_class(self, [NSGDate class]);
}
}
@ -368,7 +371,7 @@ static inline int getDigits(const char *from, char *to, int limit)
{
int year = 0, month = 1, day = 1;
int hour = 0, min = 0, sec = 0;
NSTimeZone *tz = [NSTimeZone localTimeZone];
NSTimeZone *tz = localTZ;
BOOL ampm = NO;
BOOL twelveHrClock = NO;
int julianWeeks = -1, weekStartsMonday = 0, dayOfWeek = -1;
@ -852,7 +855,7 @@ static inline int getDigits(const char *from, char *to, int limit)
if ((tz = [NSTimeZone timeZoneForSecondsFromGMT:
(zone / 100 * 60 + (zone % 100)) * 60]) == nil)
{
tz = [NSTimeZone localTimeZone];
tz = localTZ;
}
}
break;
@ -882,7 +885,7 @@ static inline int getDigits(const char *from, char *to, int limit)
}
if (tz == nil)
{
tz = [NSTimeZone localTimeZone];
tz = localTZ;
}
}
break;
@ -900,7 +903,7 @@ static inline int getDigits(const char *from, char *to, int limit)
if (tz == nil)
{
tz = [NSTimeZone localTimeZone];
tz = localTZ;
}
if (twelveHrClock == YES)
@ -1066,7 +1069,7 @@ static inline int getDigits(const char *from, char *to, int limit)
// Assign time zone detail
if (aTimeZone == nil)
{
_time_zone = RETAIN([NSTimeZone localTimeZone]);
_time_zone = RETAIN(localTZ);
}
else
{
@ -1104,14 +1107,22 @@ static inline int getDigits(const char *from, char *to, int limit)
return self;
}
// Default initializer
/**
* Initialises the receiver with the specified interval since the
* reference date. Uses th standard format string "%Y-%m-%d %H:%M:%S %z"
* and the default time zone.
*/
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
{
_seconds_since_ref = seconds;
if (_calendar_format == nil)
_calendar_format = @"%Y-%m-%d %H:%M:%S %z";
{
_calendar_format = @"%Y-%m-%d %H:%M:%S %z";
}
if (_time_zone == nil)
_time_zone = RETAIN([NSTimeZone localTimeZone]);
{
_time_zone = RETAIN(localTZ);
}
return self;
}

View file

@ -867,7 +867,7 @@ GSTimeNow()
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceNow: seconds]);
}
+ (id)dateWithTimeIntervalSince1970: (NSTimeInterval)seconds
+ (id) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds
{
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceReferenceDate:
UNIX_REFERENCE_INTERVAL + seconds]);
@ -875,7 +875,8 @@ GSTimeNow()
+ (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
{
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceReferenceDate: seconds]);
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceReferenceDate:
seconds]);
}
+ (id) distantFuture
@ -987,7 +988,7 @@ GSTimeNow()
GSTimeNow() + secsToBeAdded];
}
- (id)initWithTimeIntervalSince1970: (NSTimeInterval)seconds
- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds
{
return [self initWithTimeIntervalSinceReferenceDate:
UNIX_REFERENCE_INTERVAL + seconds];

File diff suppressed because it is too large Load diff

View file

@ -76,7 +76,7 @@ bench_object()
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
id i = [rootClass class];
[rootClass class];
}
END_TIMER;
baseline = [eTime timeIntervalSinceDate: sTime];
@ -220,7 +220,7 @@ bench_object()
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
BOOL dummy = [rootClass instancesRespondToSelector: @selector(hash)];
[rootClass instancesRespondToSelector: @selector(hash)];
}
END_TIMER;
PRINT_TIMER("ObjC: 10 inst responds to sel");
@ -341,7 +341,7 @@ bench_dict()
for (j = 0; j < 10; j++)
{
id dummy = [dict objectForKey: keys[i/10]];
[dict objectForKey: keys[i/10]];
}
}
END_TIMER;
@ -350,7 +350,7 @@ bench_dict()
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
int dummy = [dict count];
[dict count];
}
END_TIMER;
PRINT_TIMER("NSDictionary (10 count)");
@ -359,7 +359,7 @@ bench_dict()
START_TIMER;
for (i = 0; i < 10; i++)
{
BOOL dummy = [dict isEqual: obj2];
[dict isEqual: obj2];
}
END_TIMER;
PRINT_TIMER("NSDict (ten times isEqual:)");
@ -379,6 +379,7 @@ bench_str()
Class des = [NSDeserializer class];
Class md = [NSMutableDictionary class];
[[md new] release];
AUTO_START;
plist = [NSDictionary dictionaryWithObjectsAndKeys:
@ -418,7 +419,7 @@ bench_str()
START_TIMER;
for (i = 0; i < MAX_COUNT*10; i++)
{
int dummy = [str length];
[str length];
}
END_TIMER;
PRINT_TIMER("NSString (10 length) ");
@ -427,7 +428,7 @@ bench_str()
for (i = 0; i < MAX_COUNT/100; i++)
{
id arp = [NSAutoreleasePool new];
NSString *s = [plist description];
[plist description];
[arp release];
}
END_TIMER;
@ -436,7 +437,7 @@ bench_str()
START_TIMER;
for (i = 0; i < MAX_COUNT/1000; i++)
{
id p = [plstr propertyList];
[plstr propertyList];
}
END_TIMER;
PRINT_TIMER("NSString (1/1000 plparse)");
@ -460,8 +461,7 @@ bench_str()
for (i = 0; i < MAX_COUNT/100; i++)
{
NSData *d = [ser serializePropertyList: plist];
id p = [des deserializePropertyListFromData: d
mutableContainers: NO];
[des deserializePropertyListFromData: d mutableContainers: NO];
}
END_TIMER;
PRINT_TIMER("NSString (1/100 ser/des)");
@ -471,8 +471,7 @@ bench_str()
for (i = 0; i < MAX_COUNT/100; i++)
{
NSData *d = [ser serializePropertyList: plist];
id p = [des deserializePropertyListFromData: d
mutableContainers: NO];
[des deserializePropertyListFromData: d mutableContainers: NO];
}
END_TIMER;
PRINT_TIMER("NSString (1/100 ser/des - uniquing)");
@ -482,7 +481,7 @@ bench_str()
for (i = 0; i < MAX_COUNT/100; i++)
{
NSData *d = [arc archivedDataWithRootObject: plist];
id p = [una unarchiveObjectWithData: d];
[una unarchiveObjectWithData: d];
}
END_TIMER;
PRINT_TIMER("NSString (1/100 arc/una)");
@ -490,6 +489,29 @@ bench_str()
AUTO_END;
}
void
bench_date()
{
int i;
id d;
AUTO_START;
Class dateClass = [NSCalendarDate class];
printf("NSCalendarDate\n");
START_TIMER;
for (i = 0; i < MAX_COUNT/10; i++)
{
d = [[dateClass alloc] init];
[d description];
[d dayOfYear];
[d minuteOfHour];
[d release];
}
END_TIMER;
PRINT_TIMER("NSCalendarDate (various)");
AUTO_END;
}
void
bench_data()
{
@ -536,6 +558,7 @@ int main(int argc, char *argv[], char **env)
bench_str();
bench_array();
bench_dict();
bench_date();
bench_data();
AUTO_END;
return 0;

View file

@ -23,8 +23,8 @@
#include <Foundation/NSException.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSUtilities.h>
#include <Foundation/NSTimeZone.h>
#include <Foundation/NSUtilities.h>
int
main (int argc, char *argv[])
@ -36,7 +36,7 @@ main (int argc, char *argv[])
for (i = 1; i < argc; i++)
{
name = [NSString stringWithCString: argv[i]];
name = [NSString stringWithUTF8String: argv[i]];
zone = [NSTimeZone timeZoneWithName: name];
if (zone != nil)
{
@ -49,7 +49,7 @@ main (int argc, char *argv[])
[dict setObject: name forKey: [detail timeZoneAbbreviation]];
e = [dict keyEnumerator];
while ((abbrev = [e nextObject]) != nil)
printf("%@\t%@\n", abbrev, name);
printf("%s\t%s\n", [abbrev UTF8String], [name UTF8String]);
}
}

View file

@ -22,8 +22,8 @@
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSException.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSUtilities.h>
#include <Foundation/NSTimeZone.h>
#include <Foundation/NSUtilities.h>
#define HOURSECS (60*60) /* Seconds in 1 hour. */
#define DAYSECS (HOURSECS*24) /* Seconds in 24 hours. */
@ -43,7 +43,7 @@ main (int argc, char *argv[])
/* Obtain the regions for each latitudinal region. */
for (i = 1; i < argc; i++)
{
name = [NSString stringWithCString: argv[i]];
name = [NSString stringWithUTF8String: argv[i]];
zone = [NSTimeZone timeZoneWithName: name];
if (zone != nil)
{
@ -84,7 +84,7 @@ main (int argc, char *argv[])
{
e = [zones[i] objectEnumerator];
while ((name = [e nextObject]) != nil)
printf("%d %@\n", i, name);
printf("%d %s\n", i, [name UTF8String]);
}
}

View file

@ -4,18 +4,18 @@
#include <Foundation/NSArray.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSTimeZone.h>
int
main ()
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
id detail;
NSLog(@"time zones:\n%@\n", [[NSTimeZone timeZoneArray] description]);
NSLog(@"time zones for PST:\n%@\n",
[[[NSTimeZone abbreviationMap] objectForKey: @"PST"] description]);
NSLog(@"local time zone:\n%@\n", [[NSTimeZone localTimeZone] description]);
[pool release];
printf("time zones for PST:\n%s\n",
[[[[NSTimeZone abbreviationMap] objectForKey: @"PST"] description] UTF8String]);
printf("time zones:\n%s\n",
[[[NSTimeZone timeZoneArray] description] UTF8String]);
printf("local time zone:\n%s\n",
[[[NSTimeZone localTimeZone] description] UTF8String]);
return 0;
}