mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Introduces a _ThreadLocalStorage struct to hold thread-local, but global resources. Set it up to host a UBreakIterator and a cache key for resetting text. UBreakIterators are extremely expensive to create on the fly, so we store one for each thread. UBreakIterators are also expensive to bind to new text, so we cache the text it's currently bound to in order to help avoid it. The struct can be expanded with more functionality in the future, but the standard library should only ever use a single key, and thus everything should go on this struct. The _ThreadLocalStorage struct is not meant to be copyable, creatable (by anyone else except the once-per-thread initialize routine), and should accessed through the pointers it provides. Future immediate directions could include cashing multiple UBreakIterators (e.g. avoid a text reset for mutual character iteration patterns, etc). Test added in test/stdlib/ThreadLocalStorage.swift.
930 B
930 B