diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-02-14 10:49:57 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-02-15 10:35:01 +0100 |
commit | 178cae8fcb4c6cca2ec71dc3a0d2eec75ecbbc8c (patch) | |
tree | 964ab0ea263e4e46527e74b77aade4a5ceaea2d0 | |
parent | be91d666a483d0c982aea3c7b2d77a1c1dfa1bf9 (diff) | |
download | justbuild-178cae8fcb4c6cca2ec71dc3a0d2eec75ecbbc8c.tar.gz |
Remove unnecessarily quadratic expressions
... not that everyone has updated to 1.2 or later we can use
the built-in expressions "reverse" and "set".
-rw-r--r-- | rules/CC/EXPRESSIONS | 41 | ||||
-rw-r--r-- | rules/EXPRESSIONS | 70 |
2 files changed, 36 insertions, 75 deletions
diff --git a/rules/CC/EXPRESSIONS b/rules/CC/EXPRESSIONS index 24a2cfff..4f501afe 100644 --- a/rules/CC/EXPRESSIONS +++ b/rules/CC/EXPRESSIONS @@ -396,18 +396,26 @@ , "pkg-prefix-lib-paths": { "doc": ["Detect ldflags referring to local libs and prefix them."] , "vars": ["pkg-ldflags", "pkg-libs", "flat-libs", "lib-prefix"] - , "imports": {"contains": ["", "contains"]} , "expression": { "type": "let*" , "bindings": - [["list", {"type": "keys", "$1": {"type": "var", "name": "pkg-libs"}}]] + [ [ "libs set" + , { "type": "set" + , "$1": {"type": "keys", "$1": {"type": "var", "name": "pkg-libs"}} + } + ] + ] , "body": { "type": "foreach" , "var": "item" , "range": {"type": "var", "name": "pkg-ldflags"} , "body": { "type": "if" - , "cond": {"type": "CALL_EXPRESSION", "name": "contains"} + , "cond": + { "type": "lookup" + , "key": {"type": "var", "name": "item"} + , "map": {"type": "var", "name": "libs set"} + } , "then": { "type": "join" , "$1": @@ -432,14 +440,25 @@ , "pkg-prefix-flag-paths": { "doc": ["Detect flags referring to local flag files and prefix them."] , "vars": ["flags", "pkg-flag-files", "flag-prefix"] - , "imports": {"contains": ["", "contains"]} , "expression": { "type": "let*" , "bindings": - [ [ "list" - , {"type": "keys", "$1": {"type": "var", "name": "pkg-flag-files"}} + [ [ "pkg-flag-files unprefix map" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "name" + , "range": + {"type": "keys", "$1": {"type": "var", "name": "pkg-flag-files"}} + , "body": + { "type": "singleton_map" + , "key": + {"type": "join", "$1": ["@", {"type": "var", "name": "name"}]} + , "value": {"type": "var", "name": "name"} + } + } + } ] - , ["list_prefix", "@"] ] , "body": { "type": "foreach" @@ -448,7 +467,13 @@ , "body": { "type": "let*" , "bindings": - [["flag-file", {"type": "CALL_EXPRESSION", "name": "contains"}]] + [ [ "flag-file" + , { "type": "lookup" + , "map": {"type": "var", "name": "pkg-flag-files unprefix map"} + , "key": {"type": "var", "name": "item"} + } + ] + ] , "body": { "type": "if" , "cond": {"type": "var", "name": "flag-file"} diff --git a/rules/EXPRESSIONS b/rules/EXPRESSIONS index 59efead3..52a381fb 100644 --- a/rules/EXPRESSIONS +++ b/rules/EXPRESSIONS @@ -226,82 +226,18 @@ } } } -, "contains": - { "doc": ["Returns the item if it is in the list or \"null\" otherwise."] - , "vars": ["list", "item", "list_prefix"] - , "vars_doc": - { "list": ["The list to look for the item."] - , "item": ["The item to look for in the list."] - , "list_prefix": - [ "An optional string, which every item in the list is prefixed with" - , "before comparison. Note that the returned item is not prefixed." - ] - } - , "expression": - { "type": "let*" - , "bindings": - [ [ "result" - , { "type": "++" - , "$1": - { "type": "foreach" - , "var": "entry" - , "range": {"type": "var", "name": "list"} - , "body": - { "type": "if" - , "cond": - { "type": "==" - , "$1": - { "type": "join" - , "$1": - [ {"type": "var", "name": "list_prefix", "default": ""} - , {"type": "var", "name": "entry"} - ] - } - , "$2": {"type": "var", "name": "item"} - } - , "then": [{"type": "var", "name": "entry"}] - } - } - } - ] - ] - , "body": - { "type": "if" - , "cond": {"type": "var", "name": "result"} - , "then": {"type": "join", "$1": {"type": "var", "name": "result"}} - , "else": null - } - } - } -, "reverse_list": - { "doc": ["Returns the list in reverse order."] - , "vars": ["list"] - , "vars_doc": {"list": ["The list to reverse."]} - , "expression": - { "type": "foldl" - , "var": "item" - , "start": [] - , "accum_var": "out" - , "range": {"type": "var", "name": "list"} - , "body": - { "type": "++" - , "$1": - [[{"type": "var", "name": "item"}], {"type": "var", "name": "out"}] - } - } - } , "nub_left": { "doc": ["Removes all but the leftmost duplicate from the list."] , "vars": ["list"] , "vars_doc": {"list": ["The list to remove duplicates from."]} - , "imports": {"reverse": "reverse_list"} , "expression": { "type": "let*" , "bindings": - [ ["list", {"type": "CALL_EXPRESSION", "name": "reverse"}] + [ ["list", {"type": "reverse", "$1": {"type": "var", "name": "list"}}] , ["list", {"type": "nub_right", "$1": {"type": "var", "name": "list"}}] + , ["list", {"type": "reverse", "$1": {"type": "var", "name": "list"}}] ] - , "body": {"type": "CALL_EXPRESSION", "name": "reverse"} + , "body": {"type": "var", "name": "list"} } } } |