diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-10-30 13:35:48 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-11-03 18:27:13 +0100 |
commit | e45d05dfc00c809ff203457aa0da400a553a3339 (patch) | |
tree | c172fe701f9bf76ff13a8574dd65ae457b704004 /util | |
parent | 5165a5802c8e38a8eda6309af3fe68bd9d8bd8a0 (diff) |
Convert UTC offset table look-ups to binary chop
The table was almost sorted by offset - its UTC entry, with offset 0,
was at the front rather than first among the offset 0 entries. The
lookups in it were being done as if the IDs were in space-joined lists
(as for the IANA IDs in the Windows table), splitting on space,
despite the fact that it had separate entries for different IDs at the
same offset (this only arose for offset 0). So actually massage the
input table in python to combine IDs with the same offset using space,
placing UTC first among the offset 0 entries, and ensure the C++ table
is sorted. Regenerated the CLDR data tables using the updated script.
In the process, fix an off-by-one error in the iteration over
space-joined IDs, where the search only advanced to the space, rather
than to just after it. That wasn't a problem before, but now would be.
Change-Id: Ib49c27bac269b557166fa10738c3e396d58456c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'util')
-rwxr-xr-x | util/locale_database/cldr2qtimezone.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/util/locale_database/cldr2qtimezone.py b/util/locale_database/cldr2qtimezone.py index 537850a3e8..c48474ddb9 100755 --- a/util/locale_database/cldr2qtimezone.py +++ b/util/locale_database/cldr2qtimezone.py @@ -174,9 +174,9 @@ windowsIdList = ( # List of standard UTC IDs to use. Not public so may be safely changed. # Do not remove IDs, as each entry is part of the API/behavior guarantee. +# IDs for the same offset shall be space-joined; list the preferred ID first. # ( UTC Id, Offset Seconds ) utcIdList = ( - ('UTC', 0), # Goes first so is default ('UTC-14:00', -50400), ('UTC-13:00', -46800), ('UTC-12:00', -43200), @@ -193,8 +193,9 @@ utcIdList = ( ('UTC-03:00', -10800), ('UTC-02:00', -7200), ('UTC-01:00', -3600), - ('UTC-00:00', 0), # Should recognize, but avoid using (see Note below). + ('UTC', 0), # Goes first (among zero-offset) to be default ('UTC+00:00', 0), + ('UTC-00:00', 0), # Should recognize, but avoid using (see Note below). ('UTC+01:00', 3600), ('UTC+02:00', 7200), ('UTC+03:00', 10800), @@ -301,12 +302,16 @@ class ZoneIdWriter (SourceFileEditor): pair[1], pair[0])) out('};\n\n') + offsetMap = {} + for pair in utcIdList: + offsetMap[pair[1]] = offsetMap.get(pair[1], ()) + (pair[0],) # Write UTC ID key table out('// IANA ID Index, UTC Offset\n') out('static constexpr QUtcData utcDataTable[] = {\n') - for pair in utcIdList: + for offset in sorted(offsetMap.keys()): # Sort so C++ can binary-chop. + names = offsetMap[offset]; out(' {{ {:6d},{:6d} }}, // {}\n'.format( - ianaIdData.append(pair[0]), pair[1], pair[0])) + ianaIdData.append(' '.join(names)), offset, names[0])) out('};\n') return windowsIdData, ianaIdData |