Skip to content

Commit c84c179

Browse files
committed
slightly improve performance of getComponentAnnotations()
ticket:3679 do better scanning through lists
1 parent 638acf9 commit c84c179

File tree

1 file changed

+123
-146
lines changed

1 file changed

+123
-146
lines changed

Compiler/Script/Interactive.mo

Lines changed: 123 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -13415,63 +13415,62 @@ public function getComponentsInClass
1341513415
output list<Absyn.Element> outAbsynElementLst;
1341613416
algorithm
1341713417
outAbsynElementLst:=
13418-
matchcontinue (inClass)
13418+
match (inClass)
1341913419
local
13420-
String a;
13421-
Boolean b,c,d;
13422-
Absyn.Restriction e;
13423-
list<Absyn.Annotation> ann;
13424-
Option<String> cmt;
13425-
list<Absyn.Element> lst1,lst2,res;
13420+
list<Absyn.Element> lst1,res;
1342613421
list<Absyn.ElementItem> elts;
1342713422
list<Absyn.ClassPart> lst;
13428-
SourceInfo file_info;
13429-
13430-
case (Absyn.CLASS(
13431-
body = Absyn.PARTS(classParts = {}))) then {};
13432-
13433-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13434-
body = Absyn.PARTS(classParts = (Absyn.PUBLIC(contents = elts) :: lst),ann=ann,comment = cmt),info = file_info)) /* Search in public list */
13435-
equation
13436-
lst1 = getComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13437-
lst2 = getComponentsInElementitems(elts);
13438-
res = listAppend(lst2, lst1);
13439-
then
13440-
res;
1344113423

13442-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13443-
body = Absyn.PARTS(classParts = (Absyn.PROTECTED(contents = elts) :: lst),ann=ann,comment = cmt),info = file_info)) /* Search in protected list */
13444-
equation
13445-
lst1 = getComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13446-
lst2 = getComponentsInElementitems(elts);
13447-
res = listAppend(lst2, lst1);
13424+
case (Absyn.CLASS(body = Absyn.PARTS(classParts = {}))) then {};
13425+
case (Absyn.CLASS(body = Absyn.PARTS(classParts = lst)))
13426+
algorithm
13427+
res := {};
13428+
for elt in lst loop
13429+
_ := match elt
13430+
case Absyn.PUBLIC(contents = elts)
13431+
algorithm
13432+
lst1 := getComponentsInElementitems(elts);
13433+
res := List.append_reverse(lst1, res);
13434+
then ();
13435+
case Absyn.PROTECTED(contents = elts)
13436+
algorithm
13437+
lst1 := getComponentsInElementitems(elts);
13438+
res := List.append_reverse(lst1, res);
13439+
then ();
13440+
else ();
13441+
end match;
13442+
end for;
13443+
res := Dangerous.listReverseInPlace(res);
1344813444
then
1344913445
res;
1345013446

1345113447
// adrpo: handle also the case model extends X end X;
1345213448
case (Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = {}))) then {};
13453-
13454-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13455-
body = Absyn.CLASS_EXTENDS(parts = (Absyn.PUBLIC(contents = elts) :: lst),ann=ann,comment = cmt),info = file_info)) /* Search in public list */
13456-
equation
13457-
lst1 = getComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13458-
lst2 = getComponentsInElementitems(elts);
13459-
res = listAppend(lst2, lst1);
13460-
then
13461-
res;
13462-
13463-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13464-
body = Absyn.CLASS_EXTENDS(parts = (Absyn.PROTECTED(contents = elts) :: lst),ann=ann,comment = cmt),info = file_info)) /* Search in protected list */
13465-
equation
13466-
lst1 = getComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13467-
lst2 = getComponentsInElementitems(elts);
13468-
res = listAppend(lst2, lst1);
13449+
case (Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = lst)))
13450+
algorithm
13451+
res := {};
13452+
for elt in lst loop
13453+
_ := match elt
13454+
case Absyn.PUBLIC(contents = elts)
13455+
algorithm
13456+
lst1 := getComponentsInElementitems(elts);
13457+
res := List.append_reverse(lst1, res);
13458+
then ();
13459+
case Absyn.PROTECTED(contents = elts)
13460+
algorithm
13461+
lst1 := getComponentsInElementitems(elts);
13462+
res := List.append_reverse(lst1, res);
13463+
then ();
13464+
else ();
13465+
end match;
13466+
end for;
13467+
res := Dangerous.listReverseInPlace(res);
1346913468
then
1347013469
res;
1347113470

1347213471
else {};
1347313472

13474-
end matchcontinue;
13473+
end match;
1347513474
end getComponentsInClass;
1347613475

1347713476
public function getPublicComponentsInClass
@@ -13480,56 +13479,51 @@ public function getPublicComponentsInClass
1348013479
output list<Absyn.Element> outAbsynElementLst;
1348113480
algorithm
1348213481
outAbsynElementLst:=
13483-
matchcontinue (inClass)
13482+
match (inClass)
1348413483
local
13485-
String a;
13486-
Boolean b,c,d;
13487-
Absyn.Restriction e;
13488-
Option<String> cmt;
13489-
list<Absyn.Annotation> ann;
13490-
list<Absyn.Element> lst1,lst2,res;
13484+
list<Absyn.Element> lst1,res;
1349113485
list<Absyn.ElementItem> elts;
1349213486
list<Absyn.ClassPart> lst;
13493-
SourceInfo file_info;
13487+
1349413488
case (Absyn.CLASS(body = Absyn.PARTS(classParts = {}))) then {};
13495-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13496-
body = Absyn.PARTS(classParts = (Absyn.PUBLIC(contents = elts) :: lst),ann=ann,comment = cmt),
13497-
info = file_info)) // Search in public list
13498-
equation
13499-
lst1 = getPublicComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13500-
lst2 = getComponentsInElementitems(elts);
13501-
res = listAppend(lst2, lst1);
13502-
then
13503-
res;
13504-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13505-
body = Absyn.PARTS(classParts = (_ :: lst),comment = cmt, ann = ann),
13506-
info = file_info))
13507-
equation
13508-
res = getPublicComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13489+
case (Absyn.CLASS(body = Absyn.PARTS(classParts = lst)))
13490+
algorithm
13491+
res := {};
13492+
for elt in lst loop
13493+
_ := match elt
13494+
case Absyn.PUBLIC(contents = elts)
13495+
algorithm
13496+
lst1 := getComponentsInElementitems(elts);
13497+
res := List.append_reverse(lst1, res);
13498+
then ();
13499+
else ();
13500+
end match;
13501+
end for;
13502+
res := Dangerous.listReverseInPlace(res);
1350913503
then
1351013504
res;
1351113505

1351213506
// adrpo: handle also the case model extends X end X;
1351313507
case (Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = {}))) then {};
13514-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13515-
body = Absyn.CLASS_EXTENDS(parts = (Absyn.PUBLIC(contents = elts) :: lst),ann = ann,comment = cmt),
13516-
info = file_info)) // Search in public list
13517-
equation
13518-
lst1 = getPublicComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13519-
lst2 = getComponentsInElementitems(elts);
13520-
res = listAppend(lst2, lst1);
13521-
then
13522-
res;
13523-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13524-
body = Absyn.CLASS_EXTENDS(parts = (_ :: lst),ann = ann,comment = cmt),
13525-
info = file_info))
13526-
equation
13527-
res = getPublicComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13508+
case (Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = lst)))
13509+
algorithm
13510+
res := {};
13511+
for elt in lst loop
13512+
_ := match elt
13513+
case Absyn.PUBLIC(contents = elts)
13514+
algorithm
13515+
lst1 := getComponentsInElementitems(elts);
13516+
res := List.append_reverse(lst1, res);
13517+
then ();
13518+
else ();
13519+
end match;
13520+
end for;
13521+
res := Dangerous.listReverseInPlace(res);
1352813522
then
1352913523
res;
1353013524

1353113525
else {};
13532-
end matchcontinue;
13526+
end match;
1353313527
end getPublicComponentsInClass;
1353413528

1353513529
public function getProtectedComponentsInClass
@@ -13538,88 +13532,71 @@ public function getProtectedComponentsInClass
1353813532
output list<Absyn.Element> outAbsynElementLst;
1353913533
algorithm
1354013534
outAbsynElementLst:=
13541-
matchcontinue (inClass)
13535+
match (inClass)
1354213536
local
13543-
String a;
13544-
Boolean b,c,d;
13545-
Absyn.Restriction e;
13546-
Option<String> cmt;
13547-
list<Absyn.Element> lst1,lst2,res;
13537+
list<Absyn.Element> lst1,res;
1354813538
list<Absyn.ElementItem> elts;
1354913539
list<Absyn.ClassPart> lst;
13550-
SourceInfo file_info;
13551-
list<Absyn.Annotation> ann;
13552-
13553-
case (Absyn.CLASS(
13554-
body = Absyn.PARTS(classParts = {}))) then {};
1355513540

13556-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13557-
body = Absyn.PARTS(classParts = (Absyn.PROTECTED(contents = elts) :: lst),ann = ann,comment = cmt),
13558-
info = file_info)) // Search in protected list
13559-
equation
13560-
lst1 = getProtectedComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13561-
lst2 = getComponentsInElementitems(elts);
13562-
res = listAppend(lst2, lst1);
13563-
then
13564-
res;
13565-
13566-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13567-
body = Absyn.PARTS(classParts = (_ :: lst),ann = ann,comment = cmt),
13568-
info = file_info))
13569-
equation
13570-
res = getProtectedComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13541+
case (Absyn.CLASS(body = Absyn.PARTS(classParts = {}))) then {};
13542+
case (Absyn.CLASS(body = Absyn.PARTS(classParts = lst)))
13543+
algorithm
13544+
res := {};
13545+
for elt in lst loop
13546+
_ := match elt
13547+
case Absyn.PROTECTED(contents = elts)
13548+
algorithm
13549+
lst1 := getComponentsInElementitems(elts);
13550+
res := List.append_reverse(lst1, res);
13551+
then ();
13552+
else ();
13553+
end match;
13554+
end for;
13555+
res := Dangerous.listReverseInPlace(res);
1357113556
then
1357213557
res;
1357313558

1357413559
// adrpo: handle also the case model extends X end X;
1357513560
case (Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = {}))) then {};
13576-
13577-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13578-
body = Absyn.CLASS_EXTENDS(parts = (Absyn.PROTECTED(contents = elts) :: lst),ann = ann,comment = cmt),
13579-
info = file_info)) /* Search in protected list */
13580-
equation
13581-
lst1 = getProtectedComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13582-
lst2 = getComponentsInElementitems(elts);
13583-
res = listAppend(lst2, lst1);
13584-
then
13585-
res;
13586-
13587-
case (Absyn.CLASS(name = a,partialPrefix = b,finalPrefix = c,encapsulatedPrefix = d,restriction = e,
13588-
body = Absyn.CLASS_EXTENDS(parts = (_ :: lst),ann = ann,comment = cmt),
13589-
info = file_info))
13590-
equation
13591-
res = getProtectedComponentsInClass(Absyn.CLASS(a,b,c,d,e,Absyn.PARTS({},{},lst,ann,cmt),file_info));
13561+
case (Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = lst)))
13562+
algorithm
13563+
res := {};
13564+
for elt in lst loop
13565+
_ := match elt
13566+
case Absyn.PROTECTED(contents = elts)
13567+
algorithm
13568+
lst1 := getComponentsInElementitems(elts);
13569+
res := List.append_reverse(lst1, res);
13570+
then ();
13571+
else ();
13572+
end match;
13573+
end for;
13574+
res := Dangerous.listReverseInPlace(res);
1359213575
then
1359313576
res;
1359413577

1359513578
else {};
13596-
13597-
end matchcontinue;
13579+
end match;
1359813580
end getProtectedComponentsInClass;
1359913581

1360013582
protected function getComponentsInElementitems
1360113583
"Helper function to getComponentsInClass."
1360213584
input list<Absyn.ElementItem> inAbsynElementItemLst;
13603-
output list<Absyn.Element> outAbsynElementLst;
13585+
output list<Absyn.Element> outAbsynElementLst = {};
1360413586
algorithm
13605-
outAbsynElementLst:=
13606-
match (inAbsynElementItemLst)
13607-
local
13608-
list<Absyn.Element> res;
13609-
Absyn.Element elt;
13610-
list<Absyn.ElementItem> rest;
13611-
case ({}) then {};
13612-
case ((Absyn.ELEMENTITEM(element = elt) :: rest))
13613-
equation
13614-
res = getComponentsInElementitems(rest);
13615-
then
13616-
(elt :: res);
13617-
case ((_ :: rest))
13618-
equation
13619-
res = getComponentsInElementitems(rest);
13620-
then
13621-
res;
13622-
end match;
13587+
for el in inAbsynElementItemLst loop
13588+
_ := match (el)
13589+
local
13590+
Absyn.Element elt;
13591+
case Absyn.ELEMENTITEM(element = elt)
13592+
algorithm
13593+
outAbsynElementLst := elt :: outAbsynElementLst;
13594+
then ();
13595+
13596+
else ();
13597+
end match;
13598+
end for;
13599+
outAbsynElementLst := Dangerous.listReverseInPlace(outAbsynElementLst);
1362313600
end getComponentsInElementitems;
1362413601

1362513602
protected function getNthComponentInClass
@@ -13756,13 +13733,13 @@ algorithm
1375613733
end getNthComponentInClass;
1375713734

1375813735
protected function getNthComponentInElementitems
13759-
" This function takes an ElementItem list and and integer
13736+
" This function takes an ElementItem list and an integer
1376013737
and returns the nth component in the list, indexed from 1..n."
1376113738
input list<Absyn.ElementItem> inElements;
1376213739
input Integer inInteger;
1376313740
output Absyn.Element outElement;
1376413741
algorithm
13765-
outElement:= matchcontinue (inElements, inInteger)
13742+
outElement:= match (inElements, inInteger)
1376613743
local
1376713744
Boolean a;
1376813745
Option<Absyn.RedeclareKeywords> b;
@@ -13805,7 +13782,7 @@ algorithm
1380513782

1380613783
case ({},_) then fail();
1380713784

13808-
end matchcontinue;
13785+
end match;
1380913786
end getNthComponentInElementitems;
1381013787

1381113788
protected function getComponentInfo

0 commit comments

Comments
 (0)