Skip to content

Commit 58eb7f1

Browse files
Remove getenv from SystemNative_GetTimeZoneData
1 parent c2ecc1c commit 58eb7f1

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

src/native/libs/System.Native/pal_datetime_time_zone_data.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,18 @@ extern const char *g_dataIndex[];
7272
const char* SystemNative_GetTimeZoneData(const char* name, int* length)
7373
{
7474
#ifdef TZ_DATA_ENABLED
75-
static int s_disabledViaConfig;
76-
if (s_disabledViaConfig == 0)
77-
{
78-
char* isInvariantTimeZone = getenv("DOTNET_SYSTEM_TIMEZONE_INVARIANT");
79-
bool isDisabled = strcmp(isInvariantTimeZone, "true") == 0 || strcmp(isInvariantTimeZone, "1") == 0;
80-
s_disabledViaConfig = isDisabled ? 1 : -1;
81-
}
75+
// Small size and speed optimization: skip comparing the prefix.
76+
static const char TZ_PREFIX[] = "/usr/share/zoneinfo/";
77+
static const size_t TZ_PREFIX_LENGTH = STRING_LENGTH(TZ_PREFIX);
8278

83-
if (s_disabledViaConfig != 1)
79+
// TODO: use a binary search here. The index is ~500 entries long.
80+
assert(strncmp(TZ_PREFIX, name, TZ_PREFIX_LENGTH) == 0);
81+
for (size_t i = 0; i < ARRAY_SIZE(g_nameIndex); i++)
8482
{
85-
// Small size and speed optimization: skip comparing the prefix.
86-
static const char TZ_PREFIX[] = "/usr/share/zoneinfo/";
87-
static const size_t TZ_PREFIX_LENGTH = STRING_LENGTH(TZ_PREFIX);
88-
89-
// TODO: use a binary search here. The index is ~500 entries long.
90-
assert(strncmp(TZ_PREFIX, name, TZ_PREFIX_LENGTH) == 0);
91-
for (size_t i = 0; i < ARRAY_SIZE(g_nameIndex); i++)
83+
if (strcmp(name + TZ_PREFIX_LENGTH, g_nameIndex[i]) == 0)
9284
{
93-
if (strcmp(name + TZ_PREFIX_LENGTH, g_nameIndex[i]) == 0)
94-
{
95-
*length = (int)(g_dataIndex[i + 1] - g_dataIndex[i]);
96-
return g_dataIndex[i];
97-
}
85+
*length = (int)(g_dataIndex[i + 1] - g_dataIndex[i]);
86+
return g_dataIndex[i];
9887
}
9988
}
10089
#endif // TZ_DATA_ENABLED

0 commit comments

Comments
 (0)