commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r8456 - trunk/gnue-appserver/src


From: reinhard
Subject: [gnue] r8456 - trunk/gnue-appserver/src
Date: Fri, 12 May 2006 12:17:21 -0500 (CDT)

Author: reinhard
Date: 2006-05-12 12:17:21 -0500 (Fri, 12 May 2006)
New Revision: 8456

Modified:
   trunk/gnue-appserver/src/data.py
Log:
Changed some performance critical functions to just try: except KeyError:
instead of manually checking if the dictionary key existis.


Modified: trunk/gnue-appserver/src/data.py
===================================================================
--- trunk/gnue-appserver/src/data.py    2006-05-12 15:57:52 UTC (rev 8455)
+++ trunk/gnue-appserver/src/data.py    2006-05-12 17:17:21 UTC (rev 8456)
@@ -169,42 +169,18 @@
 
     # Make sure to use the proper dictionary; use the dirty tables only if a
     # dirty value is available, otherwise always use the clean tables.
-    if dirty and self.__has (table, row, field, True):
-      tables = self.__new
-    else:
-      tables = self.__old
+    # This construction with the exception is much faster than checking first
+    # if the key exists in the __new dictionary construct.
 
-    return tables [table] [row] [field]
+    if dirty:
+      try:
+        return self.__new[table][row][field]
+      except KeyError:
+        pass
+    return self.__old[table][row][field]
 
 
   # ---------------------------------------------------------------------------
-  # Return whether a certain value is stored in the clean/dirty cache
-  # ---------------------------------------------------------------------------
-
-  def __has (self, table, row, field, dirty):
-    """
-    Check wether a given table/row has a clean or dirty version of a given
-    field.
-
-    @param table: the table to be checked
-    @param row: id of the row to be checked
-    @param field: the name of the field to be checked
-    @param dirty: True if the dirty version should be checked, False otherwise
-
-    @return: True if a value for field is available, False otherwise
-    """
-
-    try:
-      (self.__old, self.__new) [dirty] [table] [row] [field]
-
-    except KeyError:
-      return False
-
-    else:
-      return True
-
-
-  # ---------------------------------------------------------------------------
   # Return whether a certain value is stored in the cache or not
   # ---------------------------------------------------------------------------
 
@@ -1828,12 +1804,12 @@
 
     checktype (field, unicode)
 
-    # If an original value is requested, set the dirty-flag to False, otherwise
-    # leave it unspecified (=None), which means use a dirty or clean value in
-    # that order.
-    dirty = (None, False) [original]
-    if self.__cache.has (self.__table, self.__row, field, dirty):
-      return self.__cache.read (self.__table, self.__row, field, dirty is None)
+    # First try to return the value from the cache. Just trying it and ignoring
+    # a KeyError exception is much faster than first checking if it exists.
+    try:
+      return self.__cache.read (self.__table, self.__row, field, not original)
+    except KeyError:
+      pass
 
     # if the record is newly inserted, it cannot have values in the backend
     # until now. So there's no need to fetch anything.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]