core: improve id generation#2584
Conversation
✅ Deploy Preview for jsonforms-examples ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
lucas-koehler
left a comment
There was a problem hiding this comment.
LGTM thanks!
There might be an edge case where freed ids are not reused:
When an id is freed that had collided with a different prefix's id, the freed low suffix may not be reused, so a later id for that prefix can get a higher number. This can't happen with the JSON-pointer scopes JSON Forms generates ids from.
AS this should not happen and does not violate the expectation of unique ids, there is no need to complicate the current code.
Introduces an `Id` object holding `createId`, `removeId` and `clearAllIds` references and routes all renderer-set callers through it. Adopters can now swap the default implementations.
`createId` previously rescanned the global id set from index 0 on every call. With N identical proposed ids this is O(N^2). Track a per-prefix `next` cursor and a reverse map from id to slot so the scan starts at the lowest unallocated index. `removeId` reuses freed slots by rewinding the cursor. All previously observable behavior is preserved.
113c10c to
37387f3
Compare
|
@sdirix For transparency: I rebased the commits onto master and changed the wording very slightly replacing |
Related to #2383