Skip to content

Commit fd6693a

Browse files
authored
Improve library loading (#8921)
- Move exactly matching versions to the head of the list when using the package manager to get compatible versions, to avoid loading other versions of libraries when the requested version exists.
1 parent 6cbe437 commit fd6693a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

OMCompiler/Compiler/FrontEnd/ClassLoader.mo

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ protected
144144
Boolean isDir, impactOK;
145145
Option<Absyn.Class> cl;
146146
list<String> versionsThatProvideTheWanted, commands, versions;
147+
list<String> exact_versions, compatible_versions;
148+
149+
function isExactVersion
150+
input String version;
151+
input String requestedVersion;
152+
output Boolean exact = Util.stringStartsWith(requestedVersion, version) and
153+
not Util.stringContainsChar(version, "-");
154+
end isExactVersion;
147155
algorithm
148156
if not requireExactVersion then
149157
if listEmpty(prios) then
@@ -155,12 +163,20 @@ algorithm
155163
versionsThatProvideTheWanted :=
156164
PackageManagement.versionsThatProvideTheWanted(id, v, printError = false);
157165

166+
(exact_versions, compatible_versions) :=
167+
List.splitOnTrue(versionsThatProvideTheWanted, function isExactVersion(requestedVersion = v));
168+
versionsThatProvideTheWanted := listAppend(exact_versions, compatible_versions);
169+
158170
if listEmpty(versionsThatProvideTheWanted) then
159171
versions := v :: versions;
160172
else
161173
versions := listAppend(versionsThatProvideTheWanted, versions);
162174
end if;
163175
end for;
176+
177+
if listEmpty(versions) then
178+
versions := prios;
179+
end if;
164180
end if;
165181
else
166182
versions := prios;

0 commit comments

Comments
 (0)