Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -183,10 +183,11 @@ OFCRC32.m \ OFConcreteArray.m \ OFConcreteColor.m \ OFConcreteCountedSet.m \ OFConcreteData.m \ + OFConcreteDate.m \ OFConcreteDictionary.m \ OFConcreteMutableArray.m \ OFConcreteMutableData.m \ OFConcreteMutableDictionary.m \ OFConcreteMutableSet.m \ @@ -208,10 +209,11 @@ OFSizeValue.m \ OFStrPTime.m \ OFSubarray.m \ OFSubdata.m \ OFTaggedPointerColor.m \ + OFTaggedPointerDate.m \ OFUTF8String.m \ ${LIBBASES_M} \ ${RUNTIME_AUTORELEASE_M} \ ${RUNTIME_INSTANCE_M} \ ${UNICODE_M} Index: src/OFColor.m ================================================================== --- src/OFColor.m +++ src/OFColor.m @@ -21,14 +21,14 @@ #import "OFConcreteColor.h" #import "OFOnce.h" #import "OFString.h" #import "OFTaggedPointerColor.h" -@interface OFColorSingleton: OFConcreteColor +@interface OFPlaceholderColor: OFColor @end -@interface OFPlaceholderColor: OFColor +@interface OFConcreteColorSingleton: OFConcreteColor @end static struct { Class isa; } placeholder; @@ -67,11 +67,11 @@ } OF_SINGLETON_METHODS @end -@implementation OFColorSingleton +@implementation OFConcreteColorSingleton OF_SINGLETON_METHODS @end @implementation OFColor + (void)initialize @@ -92,11 +92,11 @@ static OFColor *name##Color = nil; \ \ static void \ initPredefinedColor_##name(void) \ { \ - name##Color = [[OFColorSingleton alloc] \ + name##Color = [[OFConcreteColorSingleton alloc] \ initWithRed: redValue \ green: greenValue \ blue: blueValue \ alpha: 1]; \ } \ ADDED src/OFConcreteDate.h Index: src/OFConcreteDate.h ================================================================== --- src/OFConcreteDate.h +++ src/OFConcreteDate.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2008-2023 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFDate.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OFConcreteDate: OFDate +{ + OFTimeInterval _seconds; +} +@end + +OF_ASSUME_NONNULL_END ADDED src/OFConcreteDate.m Index: src/OFConcreteDate.m ================================================================== --- src/OFConcreteDate.m +++ src/OFConcreteDate.m @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2008-2023 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFConcreteDate.h" + +@implementation OFConcreteDate +- (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds +{ + self = [super initWithTimeIntervalSince1970: seconds]; + + _seconds = seconds; + + return self; +} + +- (OFTimeInterval)timeIntervalSince1970 +{ + return _seconds; +} +@end Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -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]) Index: src/OFTaggedPointerColor.h ================================================================== --- src/OFTaggedPointerColor.h +++ src/OFTaggedPointerColor.h @@ -17,12 +17,12 @@ OF_ASSUME_NONNULL_BEGIN #ifdef OF_OBJFW_RUNTIME @interface OFTaggedPointerColor: OFColor -+ (instancetype)colorWithRed: (uint8_t)red - green: (uint8_t)green - blue: (uint8_t)blue; ++ (OFTaggedPointerColor *)colorWithRed: (uint8_t)red + green: (uint8_t)green + blue: (uint8_t)blue; @end #endif OF_ASSUME_NONNULL_END Index: src/OFTaggedPointerColor.m ================================================================== --- src/OFTaggedPointerColor.m +++ src/OFTaggedPointerColor.m @@ -25,13 +25,13 @@ { if (self == [OFTaggedPointerColor class]) colorTag = objc_registerTaggedPointerClass(self); } -+ (instancetype)colorWithRed: (uint8_t)red - green: (uint8_t)green - blue: (uint8_t)blue ++ (OFTaggedPointerColor *)colorWithRed: (uint8_t)red + green: (uint8_t)green + blue: (uint8_t)blue { return objc_createTaggedPointer(colorTag, (uintptr_t)red << 16 | (uintptr_t)green << 8 | (uintptr_t)blue); } ADDED src/OFTaggedPointerDate.h Index: src/OFTaggedPointerDate.h ================================================================== --- src/OFTaggedPointerDate.h +++ src/OFTaggedPointerDate.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2008-2023 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFDate.h" + +OF_ASSUME_NONNULL_BEGIN + +#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX +@interface OFTaggedPointerDate: OFDate ++ (OFTaggedPointerDate *)dateWithUInt64TimeIntervalSince1970: (uint64_t)value; +@end +#endif + +OF_ASSUME_NONNULL_END ADDED src/OFTaggedPointerDate.m Index: src/OFTaggedPointerDate.m ================================================================== --- src/OFTaggedPointerDate.m +++ src/OFTaggedPointerDate.m @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2008-2023 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFTaggedPointerDate.h" + +#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX +static int dateTag; + +@implementation OFTaggedPointerDate ++ (void)initialize +{ + if (self == [OFTaggedPointerDate class]) + dateTag = objc_registerTaggedPointerClass(self); +} + ++ (OFTaggedPointerDate *)dateWithUInt64TimeIntervalSince1970: (uint64_t)value +{ + return objc_createTaggedPointer(dateTag, value & ~(UINT64_C(4) << 60)); +} + +- (OFTimeInterval)timeIntervalSince1970 +{ + uint64_t value = (uint64_t)object_getTaggedPointerValue(self); + + value |= UINT64_C(4) << 60; + + return OFFromBigEndianDouble(OFRawUInt64ToDouble(OFToBigEndian64( + value))); +} + +OF_SINGLETON_METHODS +@end +#endif