subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danie...@apache.org
Subject svn commit: r1420100 - /subversion/trunk/build/transform_sql.py
Date Tue, 11 Dec 2012 11:28:02 GMT
Author: danielsh
Date: Tue Dec 11 11:28:01 2012
New Revision: 1420100

URL: http://svn.apache.org/viewvc?rev=1420100&view=rev
Log:
Refactor code.  No functional change.

* build/transform_sql.py
  (operator): Import.
  (hotspots): New helper, factored out of extract_token_map().
  (extract_token_map): Rewrite in functional style.

Modified:
    subversion/trunk/build/transform_sql.py

Modified: subversion/trunk/build/transform_sql.py
URL: http://svn.apache.org/viewvc/subversion/trunk/build/transform_sql.py?rev=1420100&r1=1420099&r2=1420100&view=diff
==============================================================================
--- subversion/trunk/build/transform_sql.py (original)
+++ subversion/trunk/build/transform_sql.py Tue Dec 11 11:28:01 2012
@@ -25,6 +25,7 @@
 #
 
 
+import operator
 import os
 import re
 import sys
@@ -193,6 +194,14 @@ class NonRewritableDict(dict):
                       % (key, val, self.__getitem__(key)))
     super(NonRewritableDict, self).__setitem__(key, val)
 
+def hotspots(fd):
+  hotspot = False
+  for line in fd:
+    # hotspot is TRUE within definitions of static const svn_token_map_t[].
+    hotspot ^= int(('svn_token_map_t', '\x7d;')[hotspot] in line)
+    if hotspot:
+      yield line
+
 def extract_token_map(filename):
   try:
     fd = open(filename)
@@ -200,19 +209,13 @@ def extract_token_map(filename):
     return {}
 
   pattern = re.compile(r'"(.*?)".*(MAP_\w*)')
-  map = NonRewritableDict()
-  hotspot = False
-  for line in fd:
-    if ('svn_token_map_t', '\x7d;')[hotspot] in line:
-      # hotspot is TRUE within definitions of static const svn_token_map_t[].
-      hotspot = not hotspot
-      continue
-    if hotspot:
-      match = pattern.search(line)
-      if match:
-        val, key = match.groups()
-        map[key] = val
-  return map
+  return \
+    NonRewritableDict(
+      map(operator.itemgetter(1,0),
+        map(operator.methodcaller('groups'),
+          filter(None,
+            map(pattern.search,
+              hotspots(fd))))))
 
 def main(input_filepath, output):
   filename = os.path.basename(input_filepath)



Mime
View raw message