Improve build efficiency by preventing duplicate merges

Introduced a private property to the `NccCompiler` class, `$merged_dependencies`, to keep track of the dependencies that have already been merged. This prevents unnecessary re-merging during the build operation, potentially enhancing the efficiency of the process. The implementation involves a check for a preexisting merge before a new merge is performed. If a merge already exists, the process is skipped, thereby avoiding redundancies.
This commit is contained in:
Netkas 2023-10-18 15:56:24 -04:00
parent 12d7744e1e
commit 89d3af8680
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
2 changed files with 12 additions and 1 deletions

View file

@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This update introduces minor bug fixes.
### Fixed
- Improve build efficiency by preventing duplicate merges
## [2.0.3] - 2023-10-17

View file

@ -59,11 +59,17 @@
*/
private $project_manager;
/**
* @var array
*/
private $merged_dependencies;
/**
* @param ProjectManager $project_manager
*/
public function __construct(ProjectManager $project_manager)
{
$this->merged_dependencies = [];
$this->project_manager = $project_manager;
}
@ -89,6 +95,7 @@
*/
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT, array $options=[]): string
{
$this->merged_dependencies = [];
$configuration = $this->project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
$configuration->setOptions(array_merge($configuration->getOptions(), $options));
$static_dependencies = isset($configuration->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES]);
@ -234,13 +241,14 @@
/** @noinspection UnusedFunctionResultInspection */
$package_writer->addDependencyConfiguration($dependency);
if(!$static)
if(!$static || in_array($dependency->getName(), $this->merged_dependencies, true))
{
return;
}
$entry = (new PackageManager())->getPackageLock()->getVersionEntry($dependency->getName(), $dependency->getVersion());
$package_writer->merge((new PackageReader($entry->getShadowPackagePath($dependency->getName()))));
$this->merged_dependencies[] = $dependency->getName();
foreach($entry->getDependencies() as $sub_dependency)
{