[bitbake-devel,08/16] data_smart: Add explict None checks

Submitted by Richard Purdie on Sept. 16, 2013, 9:53 p.m. | Patch ID: 58213


Message ID 1379368413-9808-8-git-send-email-richard.purdie@linuxfoundation.org
State Accepted
Commit a4d81e44a7cd3dafb0bf12f7cac5ff511db18e60
Headers show

Commit Message

Richard Purdie Sept. 16, 2013, 9:53 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

Simple if xxx checks end up calling len(xxx). We're interested in the specific case
of None which means we can break out the iterator much earlier after the first
item. This adds in the specific tests for None in what is a hot path in the
data store code which gives small performance gains.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
 lib/bb/data_smart.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
index 1bb186e..970e404 100644
--- a/lib/bb/data_smart.py
+++ b/lib/bb/data_smart.py
@@ -588,7 +588,7 @@  class DataSmart(MutableMapping):
     def getVarFlag(self, var, flag, expand=False, noweakdefault=False):
         local_var = self._findVar(var)
         value = None
-        if local_var:
+        if local_var is not None:
             if flag in local_var:
                 value = copy.copy(local_var[flag])
             elif flag == "_content" and "defaultval" in local_var and not noweakdefault:
@@ -599,7 +599,7 @@  class DataSmart(MutableMapping):
             if flag == "_content":
                 cachename = var
             value = self.expand(value, cachename)
-        if value and flag == "_content" and local_var and "_removeactive" in local_var:
+        if value is not None and flag == "_content" and local_var is not None and "_removeactive" in local_var:
             filtered = filter(lambda v: v not in local_var["_removeactive"],
                               value.split(" "))
             value = " ".join(filtered)