Pushing stuff onto an array is /way/ more efficient than += ing it. Some

measurements tell me it's around 140 times faster.
This commit is contained in:
Ward Wouts 2002-08-01 09:22:29 +00:00
parent 941d145f5a
commit 46188608c5
2 changed files with 49 additions and 48 deletions

View file

@ -75,7 +75,7 @@ def _copy_array(array) # copies an array into @set
if (edges.length > 0) and (edges[-1] == element-1)
edges[-1] = element
else
edges += [ element-1, element ]
edges.push(element-1, element)
end
end
@ -109,7 +109,7 @@ def _copy_run_list(runlist)
print "#{i}\n" if Debuglevel > 0
begin
if i =~ /^(-?\d+)$/x
edges += [ ($1.to_i-1), $1.to_i ]
edges.push(($1.to_i-1), $1.to_i)
next
end
@ -119,7 +119,7 @@ def _copy_run_list(runlist)
print "Set::IntSpan::_copy_run_list: Bad order: #{runlist}\n"
exit
else
edges += [ ($1.to_i-1), $2.to_i ]
edges.push(($1.to_i-1), $2.to_i)
next
end
end
@ -131,13 +131,13 @@ def _copy_run_list(runlist)
exit
end
@set = {"negInf" => true}
edges += [ $1.to_i ]
edges.push($1.to_i)
next
end
if i =~ /^(-?\d+)-\)$/x
print "match rule 3\n"
edges += [ ($1.to_i-1) ]
edges.push(($1.to_i-1))
@set = {"posInf" => true}
last = true
next
@ -221,7 +221,7 @@ def run_list
if edges.length > 0
edges = ['(', edges] if @set["negInf"]
edges += [')'] if @set["posInf"]
edges.push(')') if @set["posInf"]
print edges.join("/"),"\n" if Debuglevel > 0
@ -236,11 +236,11 @@ def run_list
(upper.to_s <=> ')')!=0 and
((lower+1) == upper))
print "#{upper}\n" if Debuglevel > 0
runs += [ "#{upper}" ]
runs.push("#{upper}")
else
lower += 1 if (lower.to_s <=> "(")!=0
print "#{lower}-#{upper}\n" if Debuglevel > 0
runs += [ "#{lower}-#{upper}" ]
runs.push("#{lower}-#{upper}")
end
end
end
@ -295,22 +295,22 @@ def union(set_spec)
if (xA < xB)
iA += 1
inA = ! inA
not inB and eS += [ xA ]
not inB and eS.push(xA)
elsif (xB < xA)
iB += 1
inB = ! inB
not inA and eS += [ xB ]
not inA and eS.push(xB)
else
iA += 1
iB += 1
inA = ! inA
inB = ! inB
inA == inB and eS += [ xA ]
inA == inB and eS.push(xA)
end
end
iA < eA.length and (! inB) and eS += eA[iA..eA.length]
iB < eB.length and (! inA) and eS += eB[iB..eB.length]
iA < eA.length and (! inB) and eS.push(eA[iA..eA.length])
iB < eB.length and (! inA) and eS.push(eB[iB..eB.length])
s.set_pos_inf(@set["posInf"] || b.pos_inf)
s.set_edges(eS)
@ -341,22 +341,22 @@ def intersect(set_spec)
if (xA < xB)
iA += 1
inA = ! inA
inB and eS += [ xA ]
inB and eS.push(xA)
elsif (xB < xA)
iB += 1
inB = ! inB
inA and eS += [ xB ]
inA and eS.push(xB)
else
iA += 1
iB += 1
inA = ! inA
inB = ! inB
inA == inB and eS += [ xA ]
inA == inB and eS.push(xA)
end
end
iA < eA.length and inB and eS += eA[iA..eA.length]
iB < eB.length and inA and eS += eB[iB..eB.length]
iA < eA.length and inB and eS.push(eA[iA..eA.length])
iB < eB.length and inA and eS.push(eB[iB..eB.length])
s.set_neg_inf(@set["posInf"] && b.pos_inf)
s.set_edges(eS)
@ -386,22 +386,22 @@ def diff (set_spec)
if (xA < xB)
iA += 1
inA = ! inA
not inB and eS += [ xA ]
not inB and eS.push(xA)
elsif (xB < xA)
iB += 1
inB = ! inB
inA and eS += [ xB ]
inA and eS.push(xB)
else
iA += 1
iB += 1
inA = ! inA
inB = ! inB
inA != inB and eS += [ xA ]
inA != inB and eS.push(xA)
end
end
iA < eA.length and not inB and eS += eA[iA..eA.length]
iB < eB.length and inA and eS += eB[iB..eB.length]
iA < eA.length and not inB and eS.push(eA[iA..eA.length])
iB < eB.length and inA and eS.push(eB[iB..eB.length])
s.set_edges(eS)
@ -428,18 +428,18 @@ def xor(set_spec)
if (xA < xB)
iA += 1
eS += [ xA ]
eS.push(xA)
elsif (xB < xA)
iB += 1
eS += [ xB ]
eS.push(xB)
else
iA += 1
iB += 1
end
end
iA < eA.length and eS += eA[iA..eA.length]
iB < eB.length and eS += eB[iB..eB.length]
iA < eA.length and eS.push(eA[iA..eA.length])
iB < eB.length and eS.push(eB[iB..eB.length])
s.set_pos_inf(@set["posInf"] ^ b.pos_inf)
s.set_edges(eS)
@ -607,7 +607,7 @@ def insert(n)
end
if n > edge[-1]+1
@set["edges"] += [n-1, n]
@set["edges"].push(n-1, n)
return
elsif n > edge[-1]
@set["edges"][-1] += 1
@ -636,8 +636,8 @@ def insert(n)
lower = edge[0...i]
upper = edge[i...edge.length]
edge = lower
edge += [n-1, n]
edge += upper
edge.push(n-1, n)
edge.push(upper)
elsif (not lGap and rGap)
edge[i-1] += 1
elsif ( lGap and not rGap)