diff options
Diffstat (limited to 'src/backend/utils/adt/datetime.c')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index f0fe2e31a28..0410b8384e9 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -4140,20 +4140,17 @@ CheckDateTokenTables(void) /* * This function gets called during timezone config file load or reload * to create the final array of timezone tokens. The argument array - * is already sorted in name order. This data is in a temporary memory - * context and must be copied to somewhere permanent. + * is already sorted in name order. The data is converted to datetkn + * format and installed in *tbl, which must be allocated by the caller. */ void -InstallTimeZoneAbbrevs(tzEntry *abbrevs, int n) +ConvertTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl, + struct tzEntry *abbrevs, int n) { - datetkn *newtbl; + datetkn *newtbl = tbl->abbrevs; int i; - /* - * Copy the data into TopMemoryContext and convert to datetkn format. - */ - newtbl = (datetkn *) MemoryContextAlloc(TopMemoryContext, - n * sizeof(datetkn)); + tbl->numabbrevs = n; for (i = 0; i < n; i++) { strncpy(newtbl[i].token, abbrevs[i].abbrev, TOKMAXLEN); @@ -4163,12 +4160,20 @@ InstallTimeZoneAbbrevs(tzEntry *abbrevs, int n) /* Check the ordering, if testing */ Assert(CheckDateTokenTable("timezone offset", newtbl, n)); +} + +/* + * Install a TimeZoneAbbrevTable as the active table. + * + * Caller is responsible that the passed table doesn't go away while in use. + */ +void +InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl) +{ + int i; - /* Now safe to replace existing table (if any) */ - if (timezonetktbl) - pfree(timezonetktbl); - timezonetktbl = newtbl; - sztimezonetktbl = n; + timezonetktbl = tbl->abbrevs; + sztimezonetktbl = tbl->numabbrevs; /* clear date cache in case it contains any stale timezone names */ for (i = 0; i < MAXDATEFIELDS; i++) |