Skip to content
Permalink
Browse files

changed loading order of packages from undefined to sorted by name

  • Loading branch information...
turleypol committed Oct 12, 2019
1 parent 6950962 commit 17981fff287a038a11c6f198ad5cb96b8f42c30c
Showing with 12 additions and 9 deletions.
  1. +11 −9 pol-core/plib/pkg.cpp
  2. +1 −0 pol-core/plib/systemstate.h
@@ -7,6 +7,7 @@
#include "pkg.h"

#include "pol_global_config.h"
#include <algorithm>
#include <stdlib.h>

#include "../clib/cfgelem.h"
@@ -45,21 +46,18 @@ Package* find_package( const std::string& pkgname )

void remove_package( Package* pkg )
{
auto last = std::remove_if( systemstate.packages.begin(), systemstate.packages.end(),
std::bind2nd( std::equal_to<Package*>(), pkg ) );
auto last = std::remove( systemstate.packages.begin(), systemstate.packages.end(), pkg );
systemstate.packages.erase( last, systemstate.packages.end() );

// TODO: Check this loop. It looks odd.
// Should the loop stop after removing the package?
// Is it possible to have more than one name for the same package?

auto itr = systemstate.packages_byname.begin();
while ( itr != systemstate.packages_byname.end() )
{
auto tempitr = itr;
if ( itr->second == pkg )
{
systemstate.packages_byname.erase( itr );
break;
}
++itr;
if ( ( *tempitr ).second == pkg )
systemstate.packages_byname.erase( tempitr );
}
}

@@ -406,6 +404,10 @@ void load_packages( bool quiet )
replace_packages();

check_package_deps();
// sort pkg vector by name, so e.g. startup order is in a defined and maybe also expected order.
std::sort(
systemstate.packages.begin(), systemstate.packages.end(),
[]( const Package* pkg1, const Package* pkg2 ) { return pkg1->name() < pkg2->name(); } );
}

bool pkgdef_split( const std::string& spec, const Package* inpkg, const Package** outpkg,
@@ -32,6 +32,7 @@ class SystemState
SystemState& operator=( const SystemState& ) = delete;
void deinitialize();

// TODO: why two containers? keep the map when often name is searched?
Packages packages;
PackagesByName packages_byname;

0 comments on commit 17981ff

Please sign in to comment.
You can’t perform that action at this time.