1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
Commit graph

19 commits

Author SHA1 Message Date
Kyrylo Silin
48b6a9c3b4 rubocop: fix offences of Layout/EmptyLinesAroundClassBody cop 2018-11-04 16:50:21 +08:00
Kyrylo Silin
a4e9dd2e7d ring: rewrite the class to improve API
Currently, the Ring class is written with help of Hash as backend store.
According to the comments, the implementation should behave like a circular
buffer, however it doesn't. Upon reaching maximum capacity Ring doesn't replace
old elements but keeps writing to new cells, deleting old cells, so that the
hash contains `nil` entries.

The new implementation is based on Array and seems to be closer to the actual
Ring. Older elemens get overwritten with newer ones.

This class also includes Enumerable, however none of our APIs take advantage of
it, so it seems like an overkill. There was also a problem with with this API
because of the above-mentioned nils. For example, if the ring exceeds its
maximum size, then callin `Enumerable#first` on it returns `nil`.

The new implementation deals with this with removal of Enumerable. The `#[]`
syntax is preserved, and now `ring[0]` returns an actual element instead of
`nil`. In case users need the Enumerable functionality, they can call
`Ring#to_a` to build the array, which supports the wanted methods.

As for the speed, the new implementation is:

* slower overall because it's thread-safe
* faster without mutexes for `#<<`
* slower without mutexes for `#[]`

Benchmark for old implementation:

```
Warming up --------------------------------------
             Ring#<<   223.451k i/100ms
             Ring#[]     2.837k i/100ms
Calculating -------------------------------------
             Ring#<<    223.157B (± 3.4%) i/s -    778.097B
             Ring#[]     82.485M (± 9.4%) i/s -    402.602M in   4.957792s
```

Benchmark for this implementation:

```
Warming up --------------------------------------
             Ring#<<   211.587k i/100ms
             Ring#[]     1.974k i/100ms
Calculating -------------------------------------
             Ring#<<    211.385B (± 2.8%) i/s -    698.439B
             Ring#[]     40.292M (±17.0%) i/s -    190.069M in   4.971195s
```

The benchmark:

```rb
require './lib/pry'
require 'benchmark/ips'

Benchmark.ips do |x|
  empty_ring = Pry::Ring.new(100)
  populated_ring = Pry::Ring.new(100)
  150.times { |i| populated_ring << i }

  x.report("Ring#<<") do |times|
    empty_ring << times
  end

  x.report("Ring#[]") do |times|
    populated_ring[0]
    populated_ring[1]
    populated_ring[2]

    populated_ring[-1]
    populated_ring[-2]
    populated_ring[-3]

    populated_ring[1..2]
    populated_ring[-2..-1]
    populated_ring[-2..3]

    populated_ring[0..-1]

    populated_ring[2..-1]
    populated_ring[-1..10]

    populated_ring[-1..0]
    populated_ring[-1..1]
  end
end
```
2018-10-21 05:31:45 +08:00
Kyrylo Silin
4cc13f9a40 rubocop: fix offences of the Layout/ExtraSpacing cop 2018-10-13 00:54:00 +08:00
r-obert
7c1a652c6b
Deprecate Pry::Command#text. Please use black(), white(), etc directly (#1701)
instead (as you would with helper functions from BaseHelpers and
CommandHelpers)
2017-11-16 17:54:14 +01:00
egwspiti
c591031077 display an error message when cat is invoked without arguments. 2015-09-03 13:18:48 +03:00
Kyrylo Silin
6dc80079c9 file_formatter: call #around on Pry::Code instead of String
Fixes #1349 (Bug in `cat` since 0.10.1)
2015-02-26 09:04:42 +02:00
Matijs van Zuijlen
3376e6a0db Fix more warnings 2015-01-23 14:03:50 +01:00
Kyrylo Silin
c6f8d5c632 Revert "Get rid of Code#highlighted"
This reverts commit 5599b0a976.

And fixes jruby-head.

https://travis-ci.org/pry/pry/jobs/30420112
2014-07-20 17:32:17 -07:00
Steven Harman
7c47e0eb0f Cleanup unused local var warning
We're not using the `ext` local variable, so just ignore it by taking
the first element from the split - the filename.
2014-06-24 16:16:58 -04:00
Conrad Irwin
5599b0a976 Get rid of Code#highlighted 2014-05-09 20:16:02 -07:00
Conrad Irwin
5591367c26 Fix highlighting of cat command [Fix #1225] 2014-05-09 20:04:45 -07:00
Robert Gleeson
fd9a23eb30 update 'cat' command to use _pry_.config.default_window_size 2014-02-07 02:03:58 +01:00
yui-knk
08702ce1d8 Make file_and_line method to be public (lib/pry/commands/cat/file_formatter.rb) 2013-12-14 21:04:45 +09:00
yui-knk
4b284f9aea Fix some file paths break in Windows (#708). file_and_line methods in lib/pry/commands/cat/file_formatter.rb split file path with ':'. So if file path is 'c:/path/to/file', this method works incorrectly. This fix replace ':' to regexp 2013-12-14 20:29:42 +09:00
Shannon Skipper
ea1faa535d Add cat support for Ruby files with .rb ext omitted.
Add support for %cat with .rb ext omitted.

Allow highlighting ommitted '.rb' ext, DRY up ext checking.

Only call Pry::Code#from_file once on instantiation.
2013-11-18 15:15:28 -08:00
Shannon Skipper
abfda989be Also files relative to load path dirs.
Oops, fix typo in comments.

Switch to  backticks instead of plusses.

Set and unset  in a context.

Remove unnecessary #basename.

Remove early File#basename so relative paths actually work.
2013-11-13 21:54:10 -08:00
Conrad Irwin
71b364e97c Move all hacking of rbx paths into Pry::Code 2013-05-10 00:49:36 -07:00
John Mair
86206767f0 Pry::Command::Cat::FileFormatter: make format() private 2013-01-09 01:42:08 +01:00
John Mair
92fe82dbd6 refactor cat command
Put each output formatter (input expression, exception, file) into its own class.
2013-01-06 21:44:33 +01:00