Skip to content

Commit

Permalink
Merge pull request #120 from fatkodima/remove-eol-rubies
Browse files Browse the repository at this point in the history
Remove EOL Rubies
  • Loading branch information
SamSaffron committed Jun 19, 2024
2 parents 02b0cff + 997156b commit 3004011
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby: ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3"]
ruby: ["3.1", "3.2", "3.3"]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- Remove EOL Rubies: < 3.1 are no longer supported (use an earlier version of the gem if needed)

## 1.0.2 - 17-06-2024

- Add ability to profile commands via CLI @fatkodima
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A memory profiler for Ruby

## Requirements

Ruby(MRI) Version 2.5.0 and above.
Ruby(MRI) Version 3.1.0 and above.

## Installation

Expand Down
34 changes: 8 additions & 26 deletions lib/memory_profiler/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Helpers
def initialize
@gem_guess_cache = Hash.new
@location_cache = Hash.new { |h, k| h[k] = Hash.new.compare_by_identity }
@class_name_cache = Hash.new.compare_by_identity
@string_cache = Hash.new
end

Expand All @@ -30,34 +29,17 @@ def lookup_location(file, line)
end

KERNEL_CLASS_METHOD = Kernel.instance_method(:class)
if UnboundMethod.method_defined?(:bind_call)
def object_class(obj)
klass = obj.class rescue nil
unless Class === klass
# attempt to determine the true Class when .class returns something other than a Class
klass = KERNEL_CLASS_METHOD.bind_call(obj)
end
klass
end
else
def object_class(obj)
klass = obj.class rescue nil
unless Class === klass
# attempt to determine the true Class when .class returns something other than a Class
klass = KERNEL_CLASS_METHOD.bind(obj).call
end
klass
def object_class(obj)
klass = obj.class rescue nil
unless Class === klass
# attempt to determine the true Class when .class returns something other than a Class
klass = KERNEL_CLASS_METHOD.bind_call(obj)
end
klass
end

if Object.name.frozen? # Since Ruby 2.7 Module#name no longer allocate a new string
def lookup_class_name(klass)
((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
end
else
def lookup_class_name(klass)
@class_name_cache[klass] ||= ((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
end
def lookup_class_name(klass)
((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
end

def lookup_string(obj)
Expand Down
6 changes: 3 additions & 3 deletions memory_profiler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Gem::Specification.new do |spec|
spec.version = MemoryProfiler::VERSION
spec.authors = ["Sam Saffron"]
spec.email = ["sam.saffron@gmail.com"]
spec.description = %q{Memory profiling routines for Ruby 2.5+}
spec.summary = %q{Memory profiling routines for Ruby 2.5+}
spec.description = %q{Memory profiling routines for Ruby 3.1+}
spec.summary = %q{Memory profiling routines for Ruby 3.1+}
spec.homepage = "https://github.com/SamSaffron/memory_profiler"
spec.license = "MIT"

spec.executables = ["ruby-memory-profiler"]
spec.files = Dir["README.md", "CHANGELOG.md", "LICENSE.txt", "lib/**/*", "bin/ruby-memory-profiler"]

spec.required_ruby_version = ">= 2.5.0"
spec.required_ruby_version = ">= 3.1.0"
end
12 changes: 2 additions & 10 deletions test/test_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,7 @@ def test_no_strings_retained_report
end
end

if RUBY_VERSION < '3'
# 3 times "0", 2 times for interpolated strings
total_allocated = 5 * (3 + 2 + 2 + 2)
unique = 20
elsif RUBY_VERSION < '3.1'
# 3 times "0", 2 times for short interpolated strings, 3 times for long interpolated strings
total_allocated = 5 * (3 + 2 + 3 + 3)
unique = 20
elsif RUBY_VERSION < '3.3'
if RUBY_VERSION < '3.3'
# 2 times for short interpolated strings, 3 times for long interpolated strings
total_allocated = 5 * (2 + 3 + 3)
unique = 15
Expand All @@ -262,7 +254,7 @@ def test_symbols_report
string.to_sym
end

strings_allocated = RUBY_VERSION < '3' ? 2 : 1
strings_allocated = 1
assert_equal(strings_allocated + 1, results.total_allocated)
assert_includes(0..1, results.total_retained)
assert_equal(1, results.strings_allocated.size)
Expand Down

0 comments on commit 3004011

Please sign in to comment.