Skip to content

Commit ab183ec

Browse files
committed
Move duplicated code into its own function.
To allow easier adoption of the Android code, this duplicated piece of code is moved into its own function, since it will need to change significantly for Android.
1 parent c82e1de commit ab183ec

File tree

1 file changed

+20
-34
lines changed

1 file changed

+20
-34
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,20 @@ Boolean _CFTimeZoneInitInternal(CFTimeZoneRef timezone, CFStringRef name, CFData
10581058
return success;
10591059
}
10601060

1061+
CFDataRef _CFTimeZoneDataCreate(CFURLRef baseURL, CFStringRef tzName) {
1062+
void *bytes;
1063+
CFIndex length;
1064+
CFDataRef data = NULL;
1065+
CFURLRef tempURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, tzName, false);
1066+
if (NULL != tempURL) {
1067+
if (_CFReadBytesFromFile(kCFAllocatorSystemDefault, tempURL, &bytes, &length, 0, 0)) {
1068+
data = CFDataCreateWithBytesNoCopy(kCFAllocatorSystemDefault, bytes, length, kCFAllocatorSystemDefault);
1069+
}
1070+
CFRelease(tempURL);
1071+
}
1072+
return data;
1073+
}
1074+
10611075
Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data) {
10621076
if (!name || !__nameStringOK(name)) {
10631077
return false;
@@ -1093,9 +1107,7 @@ Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data
10931107
}
10941108

10951109
CFStringRef tzName = NULL;
1096-
CFURLRef baseURL, tempURL;
1097-
void *bytes;
1098-
CFIndex length;
1110+
CFURLRef baseURL;
10991111
Boolean result = false;
11001112

11011113
#if TARGET_OS_WIN32
@@ -1128,13 +1140,7 @@ Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data
11281140
CFDictionaryRef abbrevs = CFTimeZoneCopyAbbreviationDictionary();
11291141
tzName = CFDictionaryGetValue(abbrevs, name);
11301142
if (NULL != tzName) {
1131-
tempURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, tzName, false);
1132-
if (NULL != tempURL) {
1133-
if (_CFReadBytesFromFile(kCFAllocatorSystemDefault, tempURL, &bytes, &length, 0, 0)) {
1134-
data = CFDataCreateWithBytesNoCopy(kCFAllocatorSystemDefault, bytes, length, kCFAllocatorSystemDefault);
1135-
}
1136-
CFRelease(tempURL);
1137-
}
1143+
data = _CFTimeZoneDataCreate(baseURL, tzName);
11381144
}
11391145
CFRelease(abbrevs);
11401146

@@ -1159,13 +1165,7 @@ Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data
11591165
}
11601166
if (NULL == data) {
11611167
tzName = name;
1162-
tempURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, tzName, false);
1163-
if (NULL != tempURL) {
1164-
if (_CFReadBytesFromFile(kCFAllocatorSystemDefault, tempURL, &bytes, &length, 0, 0)) {
1165-
data = CFDataCreateWithBytesNoCopy(kCFAllocatorSystemDefault, bytes, length, kCFAllocatorSystemDefault);
1166-
}
1167-
CFRelease(tempURL);
1168-
}
1168+
data = _CFTimeZoneDataCreate(baseURL, tzName);
11691169
}
11701170
CFRelease(baseURL);
11711171
if (NULL != data) {
@@ -1311,9 +1311,7 @@ CFTimeZoneRef CFTimeZoneCreateWithName(CFAllocatorRef allocator, CFStringRef nam
13111311
}
13121312
}
13131313
}
1314-
CFURLRef baseURL, tempURL;
1315-
void *bytes;
1316-
CFIndex length;
1314+
CFURLRef baseURL;
13171315

13181316
#if TARGET_OS_WIN32
13191317
CFDictionaryRef abbrevs = CFTimeZoneCopyAbbreviationDictionary();
@@ -1344,13 +1342,7 @@ CFTimeZoneRef CFTimeZoneCreateWithName(CFAllocatorRef allocator, CFStringRef nam
13441342
CFDictionaryRef abbrevs = CFTimeZoneCopyAbbreviationDictionary();
13451343
tzName = CFDictionaryGetValue(abbrevs, name);
13461344
if (NULL != tzName) {
1347-
tempURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, tzName, false);
1348-
if (NULL != tempURL) {
1349-
if (_CFReadBytesFromFile(kCFAllocatorSystemDefault, tempURL, &bytes, &length, 0, 0)) {
1350-
data = CFDataCreateWithBytesNoCopy(kCFAllocatorSystemDefault, bytes, length, kCFAllocatorSystemDefault);
1351-
}
1352-
CFRelease(tempURL);
1353-
}
1345+
data = _CFTimeZoneDataCreate(baseURL, tzName);
13541346
}
13551347
CFRelease(abbrevs);
13561348
}
@@ -1375,13 +1367,7 @@ CFTimeZoneRef CFTimeZoneCreateWithName(CFAllocatorRef allocator, CFStringRef nam
13751367
}
13761368
if (NULL == data) {
13771369
tzName = name;
1378-
tempURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, tzName, false);
1379-
if (NULL != tempURL) {
1380-
if (_CFReadBytesFromFile(kCFAllocatorSystemDefault, tempURL, &bytes, &length, 0, 0)) {
1381-
data = CFDataCreateWithBytesNoCopy(kCFAllocatorSystemDefault, bytes, length, kCFAllocatorSystemDefault);
1382-
}
1383-
CFRelease(tempURL);
1384-
}
1370+
data = _CFTimeZoneDataCreate(baseURL, tzName);
13851371
}
13861372
CFRelease(baseURL);
13871373
if (NULL != data) {

0 commit comments

Comments
 (0)