aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/package_interface.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-19 23:45:38 +0900
committernsfisis <nsfisis@gmail.com>2026-08-19 23:45:38 +0900
commitcd7c3fce2472656b2a1247429751e43350976677 (patch)
tree95e8760e3417fc3e63dac28bc0cd823a6af768f2 /crates/shirabe/src/package/package_interface.rs
parentb8fb046bd7c4cd28598bcce9f3955d834ea5d008 (diff)
downloadphp-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/package_interface.rs')
-rw-r--r--crates/shirabe/src/package/package_interface.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/shirabe/src/package/package_interface.rs b/crates/shirabe/src/package/package_interface.rs
index ffbec286..d138fd83 100644
--- a/crates/shirabe/src/package/package_interface.rs
+++ b/crates/shirabe/src/package/package_interface.rs
@@ -159,31 +159,31 @@ pub trait PackageInterface: std::fmt::Display + std::fmt::Debug {
/// this package can be installed
///
/// @return array<string, Link> A map of package links defining required packages, indexed by the require package's name
- fn get_requires(&self) -> IndexMap<String, Link>;
+ fn get_requires(&self) -> std::rc::Rc<IndexMap<String, Link>>;
/// Returns a set of links to packages which must not be installed at the
/// same time as this package
///
/// @return array<string, Link> A map of package links defining conflicting packages
- fn get_conflicts(&self) -> IndexMap<String, Link>;
+ fn get_conflicts(&self) -> std::rc::Rc<IndexMap<String, Link>>;
/// Returns a set of links to virtual packages that are provided through
/// this package
///
/// @return array<string, Link> A map of package links defining provided packages
- fn get_provides(&self) -> IndexMap<String, Link>;
+ fn get_provides(&self) -> std::rc::Rc<IndexMap<String, Link>>;
/// Returns a set of links to packages which can alternatively be
/// satisfied by installing this package
///
/// @return array<string, Link> A map of package links defining replaced packages
- fn get_replaces(&self) -> IndexMap<String, Link>;
+ fn get_replaces(&self) -> std::rc::Rc<IndexMap<String, Link>>;
/// Returns a set of links to packages which are required to develop
/// this package. These are installed if in dev mode.
///
/// @return array<string, Link> A map of package links defining packages required for development, indexed by the require package's name
- fn get_dev_requires(&self) -> IndexMap<String, Link>;
+ fn get_dev_requires(&self) -> std::rc::Rc<IndexMap<String, Link>>;
/// Returns a set of package names and reasons why they are useful in
/// combination with this package.
@@ -192,14 +192,17 @@ pub trait PackageInterface: std::fmt::Display + std::fmt::Debug {
fn get_suggests(&self) -> IndexMap<String, String>;
/// PHP helper that switches on the link kind (require/require-dev/conflict/etc.).
- fn get_links_for_type(&self, link_type: &str) -> IndexMap<String, crate::package::Link> {
+ fn get_links_for_type(
+ &self,
+ link_type: &str,
+ ) -> std::rc::Rc<IndexMap<String, crate::package::Link>> {
match link_type {
"require" => self.get_requires(),
"require-dev" => self.get_dev_requires(),
"conflict" => self.get_conflicts(),
"provide" => self.get_provides(),
"replace" => self.get_replaces(),
- _ => IndexMap::new(),
+ _ => std::rc::Rc::new(IndexMap::new()),
}
}