1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test
schneems 2b22c93533 Compatibility with IRB
Instead of accessing the struct as an array, access it via methods. There are other places inside of this file already using this API (for example e0a5c3d2b7/lib/irb/ruby-lex.rb (L829-L830)).

This commit moves all struct array-ish calls to use their method calls instead. It is also ~1.23 faster accessing values via a method instead of as an array according to this microbenchmark:

```ruby
Elem = Struct.new(:pos, :event, :tok, :state, :message) do
  def initialize(pos, event, tok, state, message = nil)
    super(pos, event, tok, State.new(state), message)
  end

  # ...

  def to_a
    a = super
    a.pop unless a.empty?
    a
  end
end

class ElemClass
  attr_accessor :pos, :event, :tok, :state, :message

  def initialize(pos, event, tok, state, message = nil)
    @pos = pos
    @event = event
    @tok = tok
    @state = State.new(state)
    @message = message
  end

  def to_a
    if @message
      [@pos, @event, @tok, @state, @message]
    else
      [@pos, @event, @tok, @state]
    end
  end
end

# stub state class creation for now
class State; def initialize(val); end; end
```

```ruby
Benchmark.ips do |x|
  x.report("struct") { struct[1] }
  x.report("class ") { from_class.event }
  x.compare!
end; nil
```

```
Warming up --------------------------------------
              struct     1.624M i/100ms
              class      1.958M i/100ms
Calculating -------------------------------------
              struct     17.139M (± 2.6%) i/s -     86.077M in   5.025801s
              class      21.104M (± 3.4%) i/s -    105.709M in   5.015193s

Comparison:
              class : 21103826.3 i/s
              struct: 17139201.5 i/s - 1.23x  (± 0.00) slower
```
2021-12-02 15:55:42 +09:00
..
-ext- Avoid assert failure when NULL EC is expected 2021-11-22 19:29:29 -05:00
base64
benchmark
bigdecimal Import bigdecimal-3.1.0.dev 2021-10-22 15:53:49 +09:00
cgi [ruby/cgi] When parsing cookies, only decode the values 2021-11-24 19:59:00 +09:00
coverage Make Coverage suspendable (#4856) 2021-10-25 20:00:51 +09:00
csv [ruby/csv] Add support for Ractor (https://github.com/ruby/csv/pull/218) 2021-10-24 05:57:33 +09:00
date [ruby/date] check_limit: also handle symbols 2021-11-16 22:51:41 +09:00
did_you_mean Sync did_you_mean again 2021-10-22 21:00:23 -04:00
digest
drb [ruby/drb] Use omit instead of skip for test-unit 2021-09-28 17:31:08 +09:00
dtrace
erb
error_highlight [ruby/error_highlight] Make the formatter mechanism support Ractor 2021-10-27 11:29:20 +09:00
etc
excludes
fiber Suppress the “experimental" warnings for IO::Buffer 2021-11-23 16:08:53 +09:00
fiddle
fileutils
fixtures/fake_sorted_set_gem
io [ruby/io-wait] Disable ractor test which is meaningless on earlier versions 2021-11-16 20:25:44 +09:00
irb Compatibility with IRB 2021-12-02 15:55:42 +09:00
json
lib Disable YJIT in MJIT tests 2021-10-20 18:19:38 -04:00
logger [ruby/logger] Ignored loading CoreAssertions in test runner 2021-09-15 08:49:24 +09:00
mkmf Revert "mkmf.rb: try linking at try_var" [Bug #18235] 2021-10-03 18:23:39 +09:00
monitor
net Sync test_http_request.rb after fix to net-http 2021-11-15 09:31:44 -08:00
nkf
objspace [Feature #18239] Implement VWA for strings 2021-10-25 13:26:23 -04:00
open-uri
openssl test/openssl/test_ssl: adjust certificate expiry date 2021-11-11 17:59:22 +09:00
optparse [ruby/optparse] Fix typo [ci skip] 2021-11-03 19:55:24 +09:00
ostruct [ruby/ostruct] Allow properties to be accessed even when the object is moved to another Ractor (https://github.com/ruby/ostruct/pull/29) 2021-09-28 17:30:06 +09:00
pathname
psych
racc [ruby/racc] Prefer __dir__ over File.dirname(__FILE__) 2021-09-15 16:20:18 +09:00
rdoc [ruby/rdoc] Fix typos in test method names [ci skip] 2021-11-04 08:56:38 +09:00
readline test/readline/test_readline.rb: skip a test on i686-linux 2021-11-09 14:52:48 +09:00
reline [ruby/reline] Correct padding space calculation 2021-11-21 13:56:26 +09:00
resolv
rinda
ripper Hash values should be omitted in Ripper results 2021-09-11 22:03:10 +09:00
ruby Don't call + and < in Integer.times for !FIXNUM 2021-12-01 16:21:50 -08:00
rubygems [rubygems/rubygems] Provide distinguished name which will be correctly parsed. 2021-12-02 04:43:06 +09:00
socket Revert "test/socket/test_socket.rb: skip on Solaris" 2021-11-30 00:07:30 +09:00
stringio
strscan
syslog
uri 'uri/https' is needed 2021-10-22 23:56:07 +09:00
win32ole [ruby/win32ole] Scale timeout in win32ole 2021-11-25 23:53:15 +09:00
yaml
zlib [ruby/zlib] [Bug #18358] Fix crash in zlib when in progress 2021-11-24 23:01:41 +09:00
runner.rb Disable experimental warnings in test/runner.rb 2021-11-10 17:42:09 +09:00
test_abbrev.rb
test_delegate.rb
test_extlibs.rb
test_find.rb
test_forwardable.rb
test_getoptlong.rb [ruby/getoptlong] fixup 5f57f47572502173e2e8880f83ef7b3e2659f974 2021-11-11 14:00:32 +09:00
test_ipaddr.rb [ruby/ipaddr] Make IPAddr#include? consider range of argument 2021-10-11 13:50:54 +09:00
test_mutex_m.rb
test_observer.rb
test_open3.rb
test_pp.rb
test_prettyprint.rb
test_pstore.rb
test_pty.rb
test_rbconfig.rb
test_securerandom.rb
test_set.rb
test_shellwords.rb
test_singleton.rb
test_sorted_set.rb
test_syslog.rb
test_tempfile.rb
test_time.rb
test_timeout.rb [ruby/timeout] test that yield is given number of seconds 2021-09-28 06:05:50 +09:00
test_tmpdir.rb
test_trick.rb
test_tsort.rb
test_unicode_normalize.rb
test_weakref.rb