Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only initialize LLVM::Attribute's class variables on demand #15534

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/llvm/enums.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,24 @@ module LLVM
WriteOnly
ZExt

@@kind_ids = load_llvm_kinds_from_names.as(Hash(Attribute, UInt32))
@@typed_attrs = load_llvm_typed_attributes.as(Array(Attribute))
# NOTE: enum body does not allow `class_getter` or `TypeDeclaration`, hence
# the nil cast
@@kind_ids = nil.as(Hash(Attribute, UInt32)?)

protected def self.kind_ids
@@kind_ids ||= load_llvm_kinds_from_names
end

@@typed_attrs = nil.as(Array(Attribute)?)

private def self.typed_attrs
@@typed_attrs ||= load_llvm_typed_attributes
end

def each_kind(& : UInt32 ->)
kind_ids = Attribute.kind_ids
each do |member|
yield @@kind_ids[member]
yield kind_ids[member]
end
end

Expand Down Expand Up @@ -150,16 +162,16 @@ module LLVM
end

def self.kind_for(member)
@@kind_ids[member]
kind_ids[member]
end

def self.from_kind(kind)
@@kind_ids.key_for(kind)
kind_ids.key_for(kind)
end

def self.requires_type?(kind)
member = from_kind(kind)
@@typed_attrs.includes?(member)
typed_attrs.includes?(member)
end
end

Expand Down