Skip to content

Commit 29d396b

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 29d396b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 17 additions & 17 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) {

0 commit comments

Comments
 (0)