@@ -22,19 +22,21 @@ #include #include #import "OFDate.h" +#import "OFConcreteDate.h" #import "OFData.h" #import "OFDictionary.h" #import "OFMessagePackExtension.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFStrPTime.h" #import "OFString.h" #import "OFSystemInfo.h" +#import "OFTaggedPointerDate.h" #import "OFXMLAttribute.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @@ -47,50 +49,37 @@ #endif @interface OFPlaceholderDate: OFDate @end -@interface OFConcreteDate: OFDate -{ - OFTimeInterval _seconds; -} -@end - -@interface OFDateSingleton: OFConcreteDate -@end - -#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX -@interface OFTaggedPointerDate: OFDateSingleton -@end -#endif +@interface OFConcreteDateSingleton: OFConcreteDate +@end static struct { Class isa; } placeholder; -static OFDateSingleton *zeroDate, *distantFuture, *distantPast; -#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX -static int dateTag; -#endif +static OFConcreteDateSingleton *zeroDate, *distantFuture, *distantPast; static void initZeroDate(void) { - zeroDate = [[OFDateSingleton alloc] initWithTimeIntervalSince1970: 0]; + zeroDate = [[OFConcreteDateSingleton alloc] + initWithTimeIntervalSince1970: 0]; } static void initDistantFuture(void) { - distantFuture = [[OFDateSingleton alloc] + distantFuture = [[OFConcreteDateSingleton alloc] initWithTimeIntervalSince1970: 64060588800.0]; } static void initDistantPast(void) { - distantPast = [[OFDateSingleton alloc] + distantPast = [[OFConcreteDateSingleton alloc] initWithTimeIntervalSince1970: -62167219200.0]; } static OFTimeInterval now(void) @@ -259,11 +248,11 @@ seconds += -(double)tz * 60; return seconds; } -@implementation OFDateSingleton +@implementation OFConcreteDateSingleton OF_SINGLETON_METHODS @end @implementation OFPlaceholderDate #ifdef __clang__ @@ -288,12 +277,12 @@ value = OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( seconds))); /* Almost all dates fall into this range. */ if (value & (UINT64_C(4) << 60)) { - id ret = objc_createTaggedPointer(dateTag, - value & ~(UINT64_C(4) << 60)); + id ret = [OFTaggedPointerDate + dateWithUInt64TimeIntervalSince1970: value]; if (ret != nil) return ret; } #endif @@ -306,39 +295,10 @@ #endif OF_SINGLETON_METHODS @end -@implementation OFConcreteDate -- (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds -{ - self = [super initWithTimeIntervalSince1970: seconds]; - - _seconds = seconds; - - return self; -} - -- (OFTimeInterval)timeIntervalSince1970 -{ - return _seconds; -} -@end - -#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX -@implementation OFTaggedPointerDate -- (OFTimeInterval)timeIntervalSince1970 -{ - uint64_t value = (uint64_t)object_getTaggedPointerValue(self); - - value |= UINT64_C(4) << 60; - - return OFFromBigEndianDouble(OFRawUInt64ToDouble(OFToBigEndian64( - value))); -} -@end -#endif @implementation OFDate + (void)initialize { #ifdef OF_WINDOWS @@ -359,14 +319,10 @@ #ifdef OF_WINDOWS if ((module = LoadLibrary("msvcrt.dll")) != NULL) _mktime64FuncPtr = (__time64_t (*)(struct tm *)) GetProcAddress(module, "_mktime64"); #endif - -#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX - dateTag = objc_registerTaggedPointerClass([OFTaggedPointerDate class]); -#endif } + (instancetype)alloc { if (self == [OFDate class])