Commit Graph
21 Commits
Author SHA1 Message Date
Karoy Lorentey f9a6df8a55 [_RopeModule] Fix infinite loop while hashing the UTF-8 view of a multi-chunk big substring 2026-04-30 15:29:22 -07:00
Karoy Lorentey 1c69635852 Add SPDX-License-Identifier tags 2026-03-05 19:39:24 -08:00
Karoy Lorentey d9b09ecde8 Update copyright dates 2026-03-05 19:39:20 -08:00
Karoy Lorentey 9503f8fe57 Improve consistency of precondition failure messages
More uniform message strings should feel better, and they should ever so slightly reduce code size.
2026-02-04 10:27:17 -08:00
Alejandro Alonso 691855a60f Bring back _isUTF16TrailingSurrogate 2025-10-14 09:50:14 -07:00
Alejandro Alonso a1f8f33a5b Make BigString unavailable in embedded 2025-09-30 12:40:09 -07:00
Alejandro Alonso a9bfbeac39 Conditionalize big string sources on 6.2 compiler
add some more
2025-09-30 09:04:52 -07:00
Alejandro Alonso 235030c10b Refactor BigString._Chunk to be its own managed buffer of UTF8 2025-09-30 09:04:19 -07:00
Karoy Lorentey 5f03d1bc24 Adopt availability macros 2025-08-17 13:23:01 -07:00
Karoy Lorentey fc411858ee [BigString] Speed up index distance calculations
This implements a roughly 40-45% improvement for distance measurements over `BigString`’s character and Unicode Scalar views.

Interestingly, we don’t see an improvement for UTF-16 views — I’m guessing this is due to String’s breadcrumbing. (And it will go away with the upcoming UTF8Span-ification of this type.)

The benchmarks I added only show an improvement for multi-chunk big string instances, but this is merely an artifact of the specific algorithm that is being measured — for single-chunk strings, the existing measurement method is already optimal, so the new heuristic never triggers for this particular payload.
2025-06-23 15:21:40 -07:00
Karoy Lorentey 65f99e3eff [BigString] Fix character indexing operations
BigString sometimes miscounted distances in its character view due to alignment issues. Resolve this by overhauling distance calculations in the character metric:

- Introduce a `prefixSize` function in `_StringMetric`, distinct from `distance`.
- In the metric-agnostic index distance algorithm, use `prefixCount` to avoid double-counting characters that cross (or end on) chunk boundaries.
- Simplify `_StringMetric.distance` by requiring that `start <= end`.
- Crucially, change character-index operations to start by rounding each input index down to the nearest character break.
2025-06-17 17:28:02 -07:00
Karoy Lorentey e4cd17cc53 Remove support code for outdated toolchains 2024-09-25 14:14:48 -07:00
Karoy Lorentey 5e1fe6e8f0 [BigString] Fix accidentally quadratic BigString.init
When ingesting a `String` instance, `BigString` assumes that the input string has a reasonably efficient UTF-8 view.

Unfortunately, that is very much not the case when the input happens to be backed by a bridged NSString object — it appears that in this case, the ingester loop invokes some operation(s) with linear complexity in the size of the entire input, rendering the ingester’s overall complexity quadratic.

The BigString ingester is only expected to operate within a single chunk at the time. It’s unclear precisely which operation triggers the quadratic behavior; ideally we should figure it out and resolve it with a more targeted fix.

In the meantime, a blunt stopgap fix is to force-transcode the input string to UTF-8 at the time the ingester is initialized. This unnecessarily wastes some (temporary) memory on holding the transcoded string, but it avoids the quadratic cliff.
2024-07-15 13:13:44 -07:00
Karoy Lorentey ffa4a58bc1 Update remaining copyright notices 2024-02-02 16:20:22 -08:00
Karoy Lorentey 73936bba69 Expose a handful of BigString.Index methods
These help implementing conversions between String.Index and BigString.Index.
2023-04-07 19:26:47 -07:00
Karoy Lorentey 28010b2f6c Use COLLECTIONS_INTERNAL_CHECKS 2023-03-21 01:28:13 -07:00
Karoy Lorentey ad82bc3f80 Naming review 2023-03-21 01:21:43 -07:00
Karoy Lorentey 88286b661d BigString: Fix Issue in utf16.distance when endpoint is on the trailing surrogate of the first scalar in a chunk 2023-03-21 01:04:12 -07:00
Karoy Lorentey 6f3f19d1c5 _Rope → Rope 2023-03-20 23:49:57 -07:00
Karoy Lorentey 51ef8613c2 Underscore more internals 2023-03-20 22:27:32 -07:00
Karoy Lorentey 0ad7f0ce38 _BString → BigString 2023-03-20 21:20:30 -07:00