public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v1 3/5] BaseTools: AutoGen refactor to iterate less
Date: Fri,  3 Aug 2018 08:11:08 -0700	[thread overview]
Message-ID: <718ca2724d8e08de0e94c2d30c719ccd8e1a85d6.1533308890.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1533308890.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1533308890.git.jaben.carsey@intel.com>

Don't iterate over new dictionaries with one item

Create the data and then add to dictionary.

Note: if you diff ignoring whitespace changes you
can more easily see the relevant changes.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 138 ++++++++++----------
 1 file changed, 66 insertions(+), 72 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 55c84fe4fbc2..7c67f40bff00 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -2983,80 +2983,74 @@ class ModuleAutoGen(AutoGen):
         if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
             return {}
 
-        RetVal = {self.ModuleType:[]}
-
-        for ModuleType in RetVal:
-            DepexList = RetVal[ModuleType]
-            #
-            # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
-            #
-            for M in [self.Module] + self.DependentLibraryList:
-                Inherited = False
-                for D in M.Depex[self.Arch, ModuleType]:
-                    if DepexList != []:
-                        DepexList.append('AND')
-                    DepexList.append('(')
-                    #replace D with value if D is FixedAtBuild PCD
-                    NewList = []
-                    for item in D:
-                        if '.' not in item:
-                            NewList.append(item)
+        DepexList = []
+        #
+        # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
+        #
+        for M in [self.Module] + self.DependentLibraryList:
+            Inherited = False
+            for D in M.Depex[self.Arch, self.ModuleType]:
+                if DepexList != []:
+                    DepexList.append('AND')
+                DepexList.append('(')
+                #replace D with value if D is FixedAtBuild PCD
+                NewList = []
+                for item in D:
+                    if '.' not in item:
+                        NewList.append(item)
+                    else:
+                        if item not in self._FixedPcdVoidTypeDict:
+                            EdkLogger.error("build", FORMAT_INVALID, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item))
                         else:
-                            if item not in self._FixedPcdVoidTypeDict:
-                                EdkLogger.error("build", FORMAT_INVALID, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item))
-                            else:
-                                Value = self._FixedPcdVoidTypeDict[item]
-                                if len(Value.split(',')) != 16:
-                                    EdkLogger.error("build", FORMAT_INVALID,
-                                                    "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item))
-                                NewList.append(Value)
-                    DepexList.extend(NewList)
-                    if DepexList[-1] == 'END':  # no need of a END at this time
-                        DepexList.pop()
-                    DepexList.append(')')
-                    Inherited = True
-                if Inherited:
-                    EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))
-                if 'BEFORE' in DepexList or 'AFTER' in DepexList:
-                    break
-                if len(DepexList) > 0:
-                    EdkLogger.verbose('')
-        return RetVal
-
-    ## Merge dependency expression
-    #
-    #   @retval     list    The token list of the dependency expression after parsed
-    #
-    @cached_property
-    def DepexExpressionTokenList(self):
-        if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
-            return {}
-
-        RetVal = {self.ModuleType:''}
-
-        for ModuleType in RetVal:
-            DepexExpressionString = RetVal[ModuleType]
-            #
-            # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
-            #
-            for M in [self.Module] + self.DependentLibraryList:
-                Inherited = False
-                for D in M.DepexExpression[self.Arch, ModuleType]:
-                    if DepexExpressionString != '':
-                        DepexExpressionString += ' AND '
-                    DepexExpressionString += '('
-                    DepexExpressionString += D
-                    DepexExpressionString = DepexExpressionString.rstrip('END').strip()
-                    DepexExpressionString += ')'
-                    Inherited = True
-                if Inherited:
-                    EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionString))
-                if 'BEFORE' in DepexExpressionString or 'AFTER' in DepexExpressionString:
-                    break
-            if len(DepexExpressionString) > 0:
+                            Value = self._FixedPcdVoidTypeDict[item]
+                            if len(Value.split(',')) != 16:
+                                EdkLogger.error("build", FORMAT_INVALID,
+                                                "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item))
+                            NewList.append(Value)
+                DepexList.extend(NewList)
+                if DepexList[-1] == 'END':  # no need of a END at this time
+                    DepexList.pop()
+                DepexList.append(')')
+                Inherited = True
+            if Inherited:
+                EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))
+            if 'BEFORE' in DepexList or 'AFTER' in DepexList:
+                break
+            if len(DepexList) > 0:
                 EdkLogger.verbose('')
-            RetVal[ModuleType] = DepexExpressionString
-        return RetVal
+        return {self.ModuleType:DepexList}
+
+    ## Merge dependency expression
+    #
+    #   @retval     list    The token list of the dependency expression after parsed
+    #
+    @cached_property
+    def DepexExpressionTokenList(self):
+        if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
+            return {}
+
+        DepexExpressionString = ''
+        #
+        # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
+        #
+        for M in [self.Module] + self.DependentLibraryList:
+            Inherited = False
+            for D in M.DepexExpression[self.Arch, self.ModuleType]:
+                if DepexExpressionString != '':
+                    DepexExpressionString += ' AND '
+                DepexExpressionString += '('
+                DepexExpressionString += D
+                DepexExpressionString = DepexExpressionString.rstrip('END').strip()
+                DepexExpressionString += ')'
+                Inherited = True
+            if Inherited:
+                EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionString))
+            if 'BEFORE' in DepexExpressionString or 'AFTER' in DepexExpressionString:
+                break
+        if len(DepexExpressionString) > 0:
+            EdkLogger.verbose('')
+
+        return {self.ModuleType:DepexExpressionString}
 
     # Get the tiano core user extension, it is contain dependent library.
     # @retval: a list contain tiano core userextension.
-- 
2.16.2.windows.1



  parent reply	other threads:[~2018-08-03 15:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-03 15:11 [PATCH v1 0/5] Refactor AutoGen - class ModuleAutoGen Jaben Carsey
2018-08-03 15:11 ` [PATCH v1 1/5] BaseTools: AutoGen refactor ModuleAutoGen caching Jaben Carsey
2018-08-03 15:11 ` [PATCH v1 2/5] BaseTools: AutoGen - tag a function as cachable Jaben Carsey
2018-08-03 15:11 ` Jaben Carsey [this message]
2018-08-03 15:46 ` [PATCH v1 0/5] Refactor AutoGen - class ModuleAutoGen Carsey, Jaben
2018-08-13  1:21   ` Zhu, Yonghong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=718ca2724d8e08de0e94c2d30c719ccd8e1a85d6.1533308890.git.jaben.carsey@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox