1.1 --- a/optimiser.py Thu Mar 02 17:18:12 2017 +0100
1.2 +++ b/optimiser.py Thu Mar 02 17:29:06 2017 +0100
1.3 @@ -1131,31 +1131,47 @@
1.4 if new:
1.5 base = new
1.6 allocated_attrnames.add(attrname)
1.7 + else:
1.8 + raise OptimiseError, "Attribute %s cannot be explicitly positioned at %d." % \
1.9 + (attrname, len(allocated))
1.10
1.11 allocated.append(base)
1.12
1.13 # Try to allocate each attribute name in turn.
1.14
1.15 + x = 0
1.16 pos = 0
1.17
1.18 - while pos < len(rsizes):
1.19 - weight, size, free, attrname = rsizes[pos]
1.20 + while x < len(rsizes):
1.21 +
1.22 + # Obtain any previous allocation at the current position. Start at the
1.23 + # current attribute looking for allocations to combine.
1.24
1.25 - # Ignore allocated attribute names.
1.26 -
1.27 - if attrname in allocated_attrnames:
1.28 - pos += 1
1.29 - continue
1.30 + if pos < len(allocated):
1.31 + base = allocated[pos]
1.32 + free = base.count(None)
1.33 + y = x
1.34
1.35 # Obtain the object information for the attribute name.
1.36
1.37 - base = matrix[attrname]
1.38 + else:
1.39 + weight, size, free, attrname = rsizes[x]
1.40 +
1.41 + # Ignore allocated attribute names.
1.42 +
1.43 + if attrname in allocated_attrnames:
1.44 + x += 1
1.45 + continue
1.46 +
1.47 + # Start at the next attribute looking for allocations to combine.
1.48 +
1.49 + base = matrix[attrname]
1.50 + y = x + 1
1.51
1.52 # Examine attribute names that follow in the ranking, attempting to
1.53 # accumulate compatible attributes that can co-exist in the same
1.54 # position within structures.
1.55
1.56 - y = pos + 1
1.57 while y < len(rsizes):
1.58 _weight, _size, _free, _attrname = rsizes[y]
1.59
1.60 @@ -1190,8 +1206,12 @@
1.61
1.62 # Allocate the merged details at the current position.
1.63
1.64 - allocated.append(base)
1.65 - pos += 1
1.66 + if pos < len(allocated):
1.67 + allocated[pos] = base
1.68 + pos += 1
1.69 + else:
1.70 + x += 1
1.71 + allocated.append(base)
1.72
1.73 return allocations_to_sets(allocated)
1.74