[cfe-commits] r81012 - /cfe/trunk/utils/CmpDriver
Daniel Dunbar
daniel at zuster.org
Fri Sep 4 10:41:47 PDT 2009
Author: ddunbar
Date: Fri Sep 4 12:41:47 2009
New Revision: 81012
URL: http://llvm.org/viewvc/llvm-project?rev=81012&view=rev
Log:
Make CmpDriver less stupid.
Modified:
cfe/trunk/utils/CmpDriver
Modified: cfe/trunk/utils/CmpDriver
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/CmpDriver?rev=81012&r1=81011&r2=81012&view=diff
==============================================================================
--- cfe/trunk/utils/CmpDriver (original)
+++ cfe/trunk/utils/CmpDriver Fri Sep 4 12:41:47 2009
@@ -33,36 +33,26 @@
Assumes dist(X, Y) -> int and non-negative.
"""
- # Yay for simplicity over complexity.
+ def cost(a, b):
+ return sum(map(dist, a + [None] * (len(b) - len(a)), b))
- def extend(aElt, bElt, solution):
- d0,(a0,b0) = solution
- return d0 + dist(aElt,bElt), (([aElt]+a0),([bElt]+b0))
-
- def f(a, b):
- if len(a) == len(b):
- return (sum(map(dist, a, b)), (a, b))
-
- if not a or not b:
- if not a:
- a += [None] * len(b)
- else:
- b += [None] * len(a)
- return (sum(map(dist, a, b)), (a, b))
-
- if int(dist(a[0], b[0])) == 0:
- # Non-negative condition implies maximum is satisfied
- # taking this.
- return extend(a[0], b[0], f(a[1:], b[1:]))
-
- if len(a) < len(b):
- return min(f([None] + a, b),
- extend(a[0], b[0], f(a[1:], b[1:])))
- else:
- return min(f(a, [None] + b),
- extend(a[0], b[0], f(a[1:], b[1:])))
-
- return f(a, b)[1]
+ # Normalize so a is shortest.
+ if len(b) < len(a):
+ b, a = insertMinimumPadding(b, a, dist)
+ return a,b
+
+ # For each None we have to insert...
+ for i in range(len(b) - len(a)):
+ # For each position we could insert it...
+ current = cost(a, b)
+ best = None
+ for j in range(len(a) + 1):
+ a_0 = a[:j] + [None] + a[j:]
+ candidate = cost(a_0, b)
+ if best is None or candidate < best[0]:
+ best = (candidate, a_0, j)
+ a = best[1]
+ return a,b
class ZipperDiff(object):
"""ZipperDiff - Simple (slow) diff only accomodating inserts."""
@@ -131,7 +121,7 @@
args = sys.argv[1:]
driverA = os.getenv('DRIVER_A') or 'gcc'
- driverB = os.getenv('DRIVER_B') or 'xcc'
+ driverB = os.getenv('DRIVER_B') or 'clang'
infoA = captureDriverInfo(driverA, args)
infoB = captureDriverInfo(driverB, args)
@@ -191,4 +181,4 @@
sys.exit(1)
if __name__ == '__main__':
- main()
+ main()
More information about the cfe-commits
mailing list