diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-19 23:45:38 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-19 23:45:38 +0900 |
| commit | cd7c3fce2472656b2a1247429751e43350976677 (patch) | |
| tree | 95e8760e3417fc3e63dac28bc0cd823a6af768f2 /crates/shirabe/src/package/alias_package.rs | |
| parent | b8fb046bd7c4cd28598bcce9f3955d834ea5d008 (diff) | |
| download | php-shirabe-cd7c3fce2472656b2a1247429751e43350976677.tar.gz php-shirabe-cd7c3fce2472656b2a1247429751e43350976677.tar.zst php-shirabe-cd7c3fce2472656b2a1247429751e43350976677.zip | |
perf(package): hand out link maps behind Rc
PackageInterface::getRequires() and friends return the array of Link objects;
in PHP that is a copy-on-write array of object references, so a caller pays
nothing to look at it. The port returned IndexMap<String, Link> by value, so
every call deep-cloned the whole map, keys and constraints included. Pool
building calls these accessors once per package per candidate, which put
IndexMap::clone at 13.5% of `require laravel/laravel`.
Store the maps as Rc<IndexMap<String, Link>> and return a handle. Callers that
mutate the map clone it explicitly at the point of mutation, matching where PHP
would separate the array.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/alias_package.rs')
| -rw-r--r-- | crates/shirabe/src/package/alias_package.rs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs index 9df804f1..4eeb408a 100644 --- a/crates/shirabe/src/package/alias_package.rs +++ b/crates/shirabe/src/package/alias_package.rs @@ -39,15 +39,15 @@ pub struct AliasPackage { /// @var BasePackage pub(crate) alias_of: PackageHandle, /// @var Link[] - pub(crate) requires: IndexMap<String, Link>, + pub(crate) requires: std::rc::Rc<IndexMap<String, Link>>, /// @var Link[] - pub(crate) dev_requires: IndexMap<String, Link>, + pub(crate) dev_requires: std::rc::Rc<IndexMap<String, Link>>, /// @var array<string, Link> - pub(crate) conflicts: IndexMap<String, Link>, + pub(crate) conflicts: std::rc::Rc<IndexMap<String, Link>>, /// @var array<string, Link> - pub(crate) provides: IndexMap<String, Link>, + pub(crate) provides: std::rc::Rc<IndexMap<String, Link>>, /// @var array<string, Link> - pub(crate) replaces: IndexMap<String, Link>, + pub(crate) replaces: std::rc::Rc<IndexMap<String, Link>>, } impl AliasPackage { @@ -74,15 +74,15 @@ impl AliasPackage { stability, has_self_version_requires: false, alias_of, - requires: IndexMap::new(), - dev_requires: IndexMap::new(), - conflicts: IndexMap::new(), - provides: IndexMap::new(), - replaces: IndexMap::new(), + requires: std::rc::Rc::new(IndexMap::new()), + dev_requires: std::rc::Rc::new(IndexMap::new()), + conflicts: std::rc::Rc::new(IndexMap::new()), + provides: std::rc::Rc::new(IndexMap::new()), + replaces: std::rc::Rc::new(IndexMap::new()), }; for r#type in Link::types() { - let links: IndexMap<String, Link> = match r#type { + let links: std::rc::Rc<IndexMap<String, Link>> = match r#type { Link::TYPE_REQUIRE => this.alias_of.get_requires(), Link::TYPE_DEV_REQUIRE => this.alias_of.get_dev_requires(), Link::TYPE_PROVIDE => this.alias_of.get_provides(), @@ -90,7 +90,8 @@ impl AliasPackage { Link::TYPE_REPLACE => this.alias_of.get_replaces(), _ => unreachable!(), }; - let replaced = this.replace_self_version_dependencies(links, r#type); + let replaced = + std::rc::Rc::new(this.replace_self_version_dependencies((*links).clone(), r#type)); match r#type { Link::TYPE_REQUIRE => this.requires = replaced, Link::TYPE_DEV_REQUIRE => this.dev_requires = replaced, @@ -252,27 +253,27 @@ impl PackageInterface for AliasPackage { &self.pretty_version } - fn get_requires(&self) -> IndexMap<String, Link> { - self.requires.clone() + fn get_requires(&self) -> std::rc::Rc<IndexMap<String, Link>> { + std::rc::Rc::clone(&self.requires) } /// @inheritDoc - fn get_conflicts(&self) -> IndexMap<String, Link> { - self.conflicts.clone() + fn get_conflicts(&self) -> std::rc::Rc<IndexMap<String, Link>> { + std::rc::Rc::clone(&self.conflicts) } /// @inheritDoc - fn get_provides(&self) -> IndexMap<String, Link> { - self.provides.clone() + fn get_provides(&self) -> std::rc::Rc<IndexMap<String, Link>> { + std::rc::Rc::clone(&self.provides) } /// @inheritDoc - fn get_replaces(&self) -> IndexMap<String, Link> { - self.replaces.clone() + fn get_replaces(&self) -> std::rc::Rc<IndexMap<String, Link>> { + std::rc::Rc::clone(&self.replaces) } - fn get_dev_requires(&self) -> IndexMap<String, Link> { - self.dev_requires.clone() + fn get_dev_requires(&self) -> std::rc::Rc<IndexMap<String, Link>> { + std::rc::Rc::clone(&self.dev_requires) } fn get_type(&self) -> String { |
