summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-05 00:03:52 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-05 01:11:06 +0200
commit97220c973fdc6d3cfa02fe597c4301e87177603c (patch)
treec208a98c5a45a9700b8c56775e69542ef7fba44f /lib/modules.nix
parent0e120dc68f7de02ccb22df27fd15835fc6d082a4 (diff)
downloadnixpkgs-97220c973fdc6d3cfa02fe597c4301e87177603c.tar
nixpkgs-97220c973fdc6d3cfa02fe597c4301e87177603c.tar.gz
nixpkgs-97220c973fdc6d3cfa02fe597c4301e87177603c.tar.bz2
nixpkgs-97220c973fdc6d3cfa02fe597c4301e87177603c.tar.lz
nixpkgs-97220c973fdc6d3cfa02fe597c4301e87177603c.tar.xz
nixpkgs-97220c973fdc6d3cfa02fe597c4301e87177603c.tar.zst
nixpkgs-97220c973fdc6d3cfa02fe597c4301e87177603c.zip
Replace hasAttr/getAttr calls with the ? and . operators
For NixOS evaluation, this gives a ~21% reduction in the number of
values allocated and a ~4% speedup. It's also more readable.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 5ef7b4bb090..8af08522051 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -30,7 +30,7 @@ rec {
         if check && set ? _definedNames then
           fold (m: res:
             fold (name: res:
-              if hasAttr name set then res else throw "The option `${showOption (prefix ++ [name])}' defined in `${m.file}' does not exist.")
+              if set ? ${name} then res else throw "The option `${showOption (prefix ++ [name])}' defined in `${m.file}' does not exist.")
               res m.names)
             res set._definedNames
         else
@@ -94,22 +94,22 @@ rec {
           loc = prefix ++ [name];
           # Get all submodules that declare ‘name’.
           decls = concatLists (map (m:
-            if hasAttr name m.options
-              then [ { inherit (m) file; options = getAttr name m.options; } ]
+            if m.options ? ${name}
+              then [ { inherit (m) file; options = m.options.${name}; } ]
               else []
             ) options);
           # Get all submodules that define ‘name’.
           defns = concatLists (map (m:
-            if hasAttr name m.config
+            if m.config ? ${name}
               then map (config: { inherit (m) file; inherit config; })
-                (pushDownProperties (getAttr name m.config))
+                (pushDownProperties m.config.${name})
               else []
             ) configs);
           nrOptions = count (m: isOption m.options) decls;
           # Process mkMerge and mkIf properties.
           defns' = concatMap (m:
-            if hasAttr name m.config
-              then map (m': { inherit (m) file; value = m'; }) (dischargeProperties (getAttr name m.config))
+            if m.config ? ${name}
+              then map (m': { inherit (m) file; value = m'; }) (dischargeProperties m.config.${name})
               else []
             ) configs;
         in