Skip to content

parsedate: bsearch the time zones#21266

Closed
bagder wants to merge 4 commits into
masterfrom
bagder/parsedate-bsearch
Closed

parsedate: bsearch the time zones#21266
bagder wants to merge 4 commits into
masterfrom
bagder/parsedate-bsearch

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented Apr 8, 2026

There are 69 entries, bsearch is faster than linear search for random access.

This now also makes the matching case sensitive (zone names always in uppercase). No docs said otherwise and all tests assumed uppercase.

bagder added 3 commits April 8, 2026 10:30
There are 69 entries, bsearch is faster than linear search for random
access.

This now also makes the matching case sensitive (zone names always in
uppercase). No docs said otherwise and all tests assumed uppercase.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improve parsedate timezone parsing performance by switching the timezone-name lookup from linear scan to bsearch() over an alphabetically sorted table, while making timezone-name matching case-sensitive.

Changes:

  • Alphabetize the static timezone table to support binary search.
  • Add a tzcompare() comparator and use bsearch() for timezone lookups.
  • Change tzinfo.offset storage to int16_t and add curlx_strcopy() usage for building the search key.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/parsedate.c Outdated
Comment thread lib/parsedate.c
@github-actions github-actions Bot added the tests label Apr 8, 2026
@bagder bagder marked this pull request as ready for review April 8, 2026 09:13
@bagder
Copy link
Copy Markdown
Member Author

bagder commented Apr 8, 2026

augment review

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Apr 8, 2026

🤖 Augment PR Summary

Summary: This PR optimizes timezone parsing in lib/parsedate.c by switching from a linear scan to a binary search over the known timezone table.

Changes:

  • Reworks the static timezone table into an ASCII/lexicographically sorted list suitable for bsearch().
  • Adds a tzcompare() comparator and updates checktz() to build a fixed-size search key and perform the binary search.
  • Updates struct tzinfo to store offsets in int16_t (minutes) to reduce table footprint.
  • Introduces a dependency on curlx_strcopy() to safely copy non-NUL-terminated input substrings into the search key.
  • Makes timezone matching case-sensitive (zone names are defined in uppercase), aligning behavior with existing assumptions.
  • Extends tests/libtest/lib517.c with new cases to assert that lowercase zone names (e.g., cet, utc, gmt) are rejected.

Technical Notes: Correctness depends on keeping the timezone list sorted according to strcmp(), since the comparator is now case-sensitive and order-sensitive.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@bagder bagder closed this in 283db12 Apr 8, 2026
@bagder bagder deleted the bagder/parsedate-bsearch branch April 8, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants