Skip to content

Commit

Permalink
Refactor global usage of Prism::Location to minimize memory usage (#…
Browse files Browse the repository at this point in the history
…1917)

refactor usage of location to minimize memory usage
  • Loading branch information
aryan-soni authored Apr 15, 2024
1 parent 7592b54 commit 4cc5e5c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
36 changes: 28 additions & 8 deletions lib/ruby_indexer/lib/ruby_indexer/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Entry
sig { returns(String) }
attr_reader :file_path

sig { returns(Prism::Location) }
sig { returns(RubyIndexer::Location) }
attr_reader :location

sig { returns(T::Array[String]) }
Expand All @@ -20,13 +20,33 @@ class Entry
sig { returns(Symbol) }
attr_accessor :visibility

sig { params(name: String, file_path: String, location: Prism::Location, comments: T::Array[String]).void }
sig do
params(
name: String,
file_path: String,
location: T.any(Prism::Location, RubyIndexer::Location),
comments: T::Array[String],
).void
end
def initialize(name, file_path, location, comments)
@name = name
@file_path = file_path
@location = location
@comments = comments
@visibility = T.let(:public, Symbol)

@location = T.let(
if location.is_a?(Prism::Location)
Location.new(
location.start_line,
location.end_line,
location.start_column,
location.end_column,
)
else
location
end,
RubyIndexer::Location,
)
end

sig { returns(String) }
Expand All @@ -50,7 +70,7 @@ class Namespace < Entry
params(
name: String,
file_path: String,
location: Prism::Location,
location: T.any(Prism::Location, RubyIndexer::Location),
comments: T::Array[String],
).void
end
Expand Down Expand Up @@ -81,7 +101,7 @@ class Class < Namespace
params(
name: String,
file_path: String,
location: Prism::Location,
location: T.any(Prism::Location, RubyIndexer::Location),
comments: T::Array[String],
parent_class: T.nilable(String),
).void
Expand Down Expand Up @@ -181,7 +201,7 @@ class Member < Entry
params(
name: String,
file_path: String,
location: Prism::Location,
location: T.any(Prism::Location, RubyIndexer::Location),
comments: T::Array[String],
owner: T.nilable(Entry::Namespace),
).void
Expand Down Expand Up @@ -219,7 +239,7 @@ class Method < Member
params(
name: String,
file_path: String,
location: Prism::Location,
location: T.any(Prism::Location, RubyIndexer::Location),
comments: T::Array[String],
parameters_node: T.nilable(Prism::ParametersNode),
owner: T.nilable(Entry::Namespace),
Expand Down Expand Up @@ -349,7 +369,7 @@ class UnresolvedAlias < Entry
nesting: T::Array[String],
name: String,
file_path: String,
location: Prism::Location,
location: T.any(Prism::Location, RubyIndexer::Location),
comments: T::Array[String],
).void
end
Expand Down
26 changes: 26 additions & 0 deletions lib/ruby_indexer/lib/ruby_indexer/location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# typed: strict
# frozen_string_literal: true

module RubyIndexer
class Location
extend T::Sig

sig { returns(Integer) }
attr_reader :start_line, :end_line, :start_column, :end_column

sig do
params(
start_line: Integer,
end_line: Integer,
start_column: Integer,
end_column: Integer,
).void
end
def initialize(start_line, end_line, start_column, end_column)
@start_line = start_line
@end_line = end_line
@start_column = start_column
@end_column = end_column
end
end
end
1 change: 1 addition & 0 deletions lib/ruby_indexer/ruby_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require "ruby_indexer/lib/ruby_indexer/entry"
require "ruby_indexer/lib/ruby_indexer/configuration"
require "ruby_indexer/lib/ruby_indexer/prefix_tree"
require "ruby_indexer/lib/ruby_indexer/location"

module RubyIndexer
@configuration = T.let(Configuration.new, Configuration)
Expand Down

0 comments on commit 4cc5e5c

Please sign in to comment.