* tool/transcode-tblgen.rb (each_firstbyte_range): tuned for less

method calls.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-03-20 02:32:40 +00:00
Родитель 7fde261963
Коммит 772cc7a4f2
2 изменённых файлов: 39 добавлений и 28 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Sat Mar 20 11:32:18 2010 Tanaka Akira <akr@fsij.org>
* tool/transcode-tblgen.rb (each_firstbyte_range): tuned for less
method calls.
Sat Mar 20 00:59:50 2010 wanabe <s.wanabe@gmail.com> Sat Mar 20 00:59:50 2010 wanabe <s.wanabe@gmail.com>
* ext/dl/lib/dl/pack.rb (DL#pack): allow LLP64. * ext/dl/lib/dl/pack.rb (DL#pack): allow LLP64.

Просмотреть файл

@ -189,7 +189,7 @@ class ActionMap
end end
def self.build_tree(rects) def self.build_tree(rects)
expand("", rects) {|prefix, actions| expand(rects) {|prefix, actions|
unambiguous_action(actions) unambiguous_action(actions)
} }
end end
@ -210,7 +210,7 @@ class ActionMap
all_rects.concat rects.map {|min, max, action| [min, max, [i, action]] } all_rects.concat rects.map {|min, max, action| [min, max, [i, action]] }
} }
tree = expand("", all_rects) {|prefix, actions| tree = expand(all_rects) {|prefix, actions|
args = Array.new(rects_list.length) { [] } args = Array.new(rects_list.length) { [] }
actions.each {|i, action| actions.each {|i, action|
args[i] << action args[i] << action
@ -225,7 +225,7 @@ class ActionMap
merge_rects(*mappings.map {|m| parse_to_rects(m) }, &block) merge_rects(*mappings.map {|m| parse_to_rects(m) }, &block)
end end
def self.expand(prefix, rects, &block) def self.expand(rects, &block)
#numsing = numreg = 0 #numsing = numreg = 0
#rects.each {|min, max, action| if min == max then numsing += 1 else numreg += 1 end } #rects.each {|min, max, action| if min == max then numsing += 1 else numreg += 1 end }
#puts "#{numsing} singleton mappings and #{numreg} region mappings." #puts "#{numsing} singleton mappings and #{numreg} region mappings."
@ -241,13 +241,13 @@ class ActionMap
} }
@singleton_rects = singleton_rects.sort_by {|min, max, action| min } @singleton_rects = singleton_rects.sort_by {|min, max, action| min }
@singleton_rects.reverse! @singleton_rects.reverse!
ret = expand_rec(prefix, region_rects, &block) ret = expand_rec("", region_rects, &block)
@singleton_rects = nil @singleton_rects = nil
ret ret
end end
def self.expand_rec(prefix, region_rects, &block) def self.expand_rec(prefix, region_rects, &block)
return [] if region_rects.empty? && (!(s_rect = @singleton_rects.last) || !s_rect[0].start_with?(prefix)) return region_rects if region_rects.empty? && !((s_rect = @singleton_rects.last) && s_rect[0].start_with?(prefix))
if region_rects.empty? ? s_rect[0].length == prefix.length : region_rects[0][0].empty? if region_rects.empty? ? s_rect[0].length == prefix.length : region_rects[0][0].empty?
h = {} h = {}
while (s_rect = @singleton_rects.last) && s_rect[0].start_with?(prefix) while (s_rect = @singleton_rects.last) && s_rect[0].start_with?(prefix)
@ -259,9 +259,8 @@ class ActionMap
raise ArgumentError, "ambiguous pattern: #{prefix}" if !min.empty? raise ArgumentError, "ambiguous pattern: #{prefix}" if !min.empty?
h[action] = true h[action] = true
} }
actions = h.keys tree = Action.new(block.call(prefix, h.keys))
act = block.call(prefix, actions) h.clear
tree = Action.new(act)
else else
tree = [] tree = []
each_firstbyte_range(prefix, region_rects) {|byte_min, byte_max, r_rects2| each_firstbyte_range(prefix, region_rects) {|byte_min, byte_max, r_rects2|
@ -308,41 +307,46 @@ class ActionMap
} }
} }
r_start = nil index_from.clear
r_rects = []
until region_rects_ary.empty? || !(s_rect = @singleton_rects.last) || !(seq = s_rect[0]).start_with?(prefix) r_rects = region_rects_ary.pop
region_byte = byte_from.last region_byte = byte_from.pop
prev_r_start = region_byte
prev_r_rects = []
while r_rects && (s_rect = @singleton_rects.last) && (seq = s_rect[0]).start_with?(prefix)
singleton_byte = seq[prefix.length, 2].to_i(16) singleton_byte = seq[prefix.length, 2].to_i(16)
min_byte = singleton_byte < region_byte ? singleton_byte : region_byte min_byte = singleton_byte < region_byte ? singleton_byte : region_byte
if r_start && r_start < min_byte && !r_rects.empty? if prev_r_start < min_byte && !prev_r_rects.empty?
yield r_start, min_byte-1, r_rects yield prev_r_start, min_byte-1, prev_r_rects
end end
if region_byte < singleton_byte if region_byte < singleton_byte
r_start = region_byte prev_r_start = region_byte
prev_r_rects = r_rects
r_rects = region_rects_ary.pop r_rects = region_rects_ary.pop
byte_from.pop region_byte = byte_from.pop
elsif region_byte > singleton_byte elsif region_byte > singleton_byte
yield singleton_byte, singleton_byte, r_rects yield singleton_byte, singleton_byte, prev_r_rects
r_start = singleton_byte+1 prev_r_start = singleton_byte+1
else # region_byte == singleton_byte else # region_byte == singleton_byte
r_start = region_byte+1 prev_r_start = region_byte+1
prev_r_rects = r_rects
r_rects = region_rects_ary.pop r_rects = region_rects_ary.pop
byte_from.pop region_byte = byte_from.pop
yield singleton_byte, singleton_byte, r_rects yield singleton_byte, singleton_byte, prev_r_rects
end end
end end
until region_rects_ary.empty? while r_rects
region_byte = byte_from.last if prev_r_start < region_byte && !prev_r_rects.empty?
if r_start && r_start < region_byte && !r_rects.empty? yield prev_r_start, region_byte-1, prev_r_rects
yield r_start, region_byte-1, r_rects
end end
r_start = region_byte prev_r_start = region_byte
prev_r_rects = r_rects
r_rects = region_rects_ary.pop r_rects = region_rects_ary.pop
byte_from.pop region_byte = byte_from.pop
end end
until !(s_rect = @singleton_rects.last) || !(seq = s_rect[0]).start_with?(prefix) while (s_rect = @singleton_rects.last) && (seq = s_rect[0]).start_with?(prefix)
singleton_byte = seq[prefix.length, 2].to_i(16) singleton_byte = seq[prefix.length, 2].to_i(16)
yield singleton_byte, singleton_byte, [] yield singleton_byte, singleton_byte, []
end end
@ -504,6 +508,7 @@ class ActionMap
end end
offsets[byte] = o offsets[byte] = o
} }
infomap.clear
if !min if !min
min = max = 0 min = max = 0
end end
@ -738,6 +743,7 @@ def transcode_compile_tree(name, from, map, valid_encoding=nil)
else else
am = ActionMap.parse(h) am = ActionMap.parse(h)
end end
h.clear
max_input = am.max_input_length max_input = am.max_input_length
defined_name = am.gennode(TRANSCODE_GENERATED_BYTES_CODE, TRANSCODE_GENERATED_WORDS_CODE, name) defined_name = am.gennode(TRANSCODE_GENERATED_BYTES_CODE, TRANSCODE_GENERATED_WORDS_CODE, name)