mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 18:18:35 +00:00
Artboards: Convert to Artboards gives each new artboard its id without reading every artboard
Convert to Artboards found the highest artboard id twice for each object it converted: once for the new artboard's name and once in Document::next_artboard_id. Converting N objects read about N^2 artboards. The command now keeps the highest id as it adds artboards, and Document::next_artboard_id_above gives the next id from it. When an artboard has id u32::MAX, it falls back to next_artboard_id, which takes the smallest free id. The ids and names it gives are unchanged.
This commit is contained in:
@@ -503,6 +503,19 @@ impl Document {
|
||||
id
|
||||
}
|
||||
|
||||
/// [`Document::next_artboard_id`] when `top` is the highest id the artboards have (`None`: there
|
||||
/// are none). It reads no artboard unless that id is `u32::MAX`, so a caller that adds many
|
||||
/// artboards and keeps `top` up to date gets each id in constant time.
|
||||
pub fn next_artboard_id_above(&self, top: Option<u32>) -> u32 {
|
||||
match top.unwrap_or(0).max(self.retired_artboard_id.get()).checked_add(1) {
|
||||
Some(id) => {
|
||||
self.retired_artboard_id.raise(id);
|
||||
id
|
||||
}
|
||||
None => self.next_artboard_id(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Record that the artboard with `id` was deleted: no later artboard takes its id.
|
||||
pub fn retire_artboard_id(&self, id: u32) {
|
||||
self.retired_artboard_id.raise(id);
|
||||
|
||||
Reference in New Issue
Block a user