Skip to content

Commit

Permalink
Merge pull request #1495 from ksss/runtime-performance
Browse files Browse the repository at this point in the history
[prototype runtime] Optimize performance
  • Loading branch information
soutaro committed Sep 5, 2023
2 parents a76d118 + 650e6c8 commit a804a9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/rbs/prototype/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Runtime
def initialize(patterns:, env:, merge:, owners_included: [])
@patterns = patterns
@decls = nil
@modules = []
@modules = {}
@env = env
@merge = merge
@owners_included = owners_included.map do |name|
Expand Down Expand Up @@ -47,8 +47,11 @@ def parse(file)
def decls
unless @decls
@decls = []
@modules = ObjectSpace.each_object(Module).to_a
@modules.select {|mod| target?(mod) }.sort_by{|mod| const_name!(mod) }.each do |mod|
@modules = ObjectSpace.each_object(Module)
.map { |mod| [const_name(mod), mod] }
.select { |name, _| name }
.to_h
@modules.select { |name, mod| target?(mod) }.sort_by { |name, _| name }.each do |_, mod|
case mod
when Class
generate_class mod
Expand Down Expand Up @@ -518,7 +521,7 @@ def ensure_outer_module_declarations(mod)

outer_module_names&.each_with_index do |outer_module_name, i|
current_name = outer_module_names.take(i+1).join('::')
outer_module = @modules.detect { |x| const_name(x) == current_name }
outer_module = @modules[current_name]
outer_decl = destination.detect do |decl|
case outer_module
when Class
Expand Down
2 changes: 1 addition & 1 deletion sig/prototype/runtime.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module RBS
class Runtime
@decls: Array[AST::Declarations::t]?

@modules: Array[Module]
@modules: Hash[String, Module]

@builder: DefinitionBuilder

Expand Down

0 comments on commit a804a9c

Please sign in to comment.