character_set 1.3.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae7ec84b0727a804bf4d82564e6609fdd0bf070fd0e20c0a5688b579e320bc30
4
- data.tar.gz: b73dec9fbd4abf83fae5881de89e4e1876e48bcefc3ef935401d5adbeb9c6c8e
3
+ metadata.gz: e216e6c199ac9443cda9180a9e35d5ed92b50b45c12e7f64f45d74ecd2cf08d6
4
+ data.tar.gz: 5f3634d426dc33875d6c197ce75466544d97808b1e8b1858ac56d93422b226e8
5
5
  SHA512:
6
- metadata.gz: 2b84916c89dcd6a234cc5acedfc604f664a9e285c92b3bae6bade748ad3d9c275fb3307fb5721142e52dbedc9b16da65285a8ebd87cd686b55391f222ef1b4f8
7
- data.tar.gz: 25147010da0adfd869891d50d51e265c2b4f28e1b0cb70727d9784b11c3944b9a06a9844a2068f529e487028c214f44e2ab60271a9a5730cdd40bb04dd989aaf
6
+ metadata.gz: d24cfaa40b6e4e472e1f76cc8b6f7f3f1282e6830c0cbf76c4810c0f6f365c7419a19816d0b741cee99eb428dae03fc1d60eecab7d1ba6d210015f0cf2d5ee14
7
+ data.tar.gz: 2bd7ea63b286e106358293b1428a687374d0cd2cdc985b2da5b5cf1f45c6c541cb0ddde5b06477243cf4011065cfac7fa6bb8a521fb144a750c90039d268f03b
data/.gitattributes CHANGED
@@ -1,3 +1,3 @@
1
1
  *.cps linguist-detectable=false
2
2
  benchmarks/* linguist-detectable=false
3
- spec/ruby-spec/* linguist-vendored
3
+ spec/* linguist-detectable=false
@@ -0,0 +1,20 @@
1
+ name: gouteur
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ - name: Prepare
16
+ run: |
17
+ bundle install --jobs 4
18
+ bundle exec rake compile
19
+ - name: Test
20
+ run: bundle exec gouteur
@@ -0,0 +1,29 @@
1
+ # based on https://github.com/rails/rails/blob/4a78dcb/.github/workflows/rubocop.yml
2
+
3
+ name: rubocop linting
4
+
5
+ on: [push, pull_request]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.7
17
+ - name: Cache gems
18
+ uses: actions/cache@v1
19
+ with:
20
+ path: vendor/bundle
21
+ key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
22
+ restore-keys: |
23
+ ${{ runner.os }}-rubocop-
24
+ - name: Install gems
25
+ run: |
26
+ bundle config path vendor/bundle
27
+ bundle install --jobs 4 --retry 3
28
+ - name: Run rubocop
29
+ run: bundle exec rubocop --lint
@@ -0,0 +1,26 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ schedule:
7
+ - cron: '11 11 14 * *' # at 11:11 am on the 14th of every month
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby: [ '2.2', '2.7', '3.0', '3.1', 'ruby-head', 'jruby-head' ]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby ${{ matrix.ruby }}
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - name: Install dependencies
24
+ run: bundle install --jobs 4
25
+ - name: Test with Rake
26
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -15,6 +15,7 @@
15
15
  .ruby-version
16
16
  .tags
17
17
  .tags1
18
+ .tool-versions
18
19
  .vscode
19
20
  bbin/
20
21
  binstubs/*
data/.gouteur.yml ADDED
@@ -0,0 +1,2 @@
1
+ repos:
2
+ - uri: https://github.com/jaynetics/js_regex
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Exclude:
3
+ - '**/doc/*'
4
+ - '**/pkg/*'
5
+ - '**/spec/ruby-spec/**/*'
6
+ - '**/vendor/**/*' # vendored dependencies
7
+ NewCops: enable
8
+ RubyInterpreters:
9
+ - ruby
10
+ - rake
11
+ TargetRubyVersion: 2.5 # really 2.1, but 2.5 is lowest supported by rubocop
12
+
13
+ Lint/AmbiguousOperatorPrecedence:
14
+ Enabled: false
15
+
16
+ Lint/AmbiguousRegexpLiteral:
17
+ Enabled: false
data/BENCHMARK.md CHANGED
@@ -1,86 +1,90 @@
1
- Results of `rake:benchmark` on ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
1
+ Results of `rake:benchmark` on ruby 3.2.0dev (2022-02-14T14:35:54Z master 26187a8520) [arm64-darwin21]
2
2
 
3
3
  ```
4
4
  Counting non-letters
5
5
 
6
- CharacterSet#count_in: 12253693.8 i/s
7
- String#count: 1737741.7 i/s - 7.05x slower
6
+ CharacterSet#count_in: 14794607.9 i/s
7
+ String#count: 3875939.3 i/s - 3.82x slower
8
8
  ```
9
9
  ```
10
10
  Detecting non-whitespace
11
11
 
12
- CharacterSet#cover?: 14058351.9 i/s
13
- Regexp#match?: 7907608.1 i/s - 1.78x slower
12
+ CharacterSet#cover?: 17448329.0 i/s
13
+ Regexp#match?: 13089358.1 i/s - 1.33x slower
14
14
  ```
15
15
  ```
16
16
  Detecting non-letters
17
17
 
18
- CharacterSet#cover?: 13341301.6 i/s
19
- Regexp#match?: 5187453.3 i/s - 2.57x slower
18
+ CharacterSet#cover?: 17565596.9 i/s
19
+ Regexp#match?: 7951108.0 i/s - 2.21x slower
20
20
  ```
21
21
  ```
22
- Removing whitespace
22
+ Removing ASCII whitespace
23
23
 
24
- CharacterSet#delete_in: 2523184.0 i/s
25
- String#gsub: 225804.7 i/s - 11.17x slower
24
+ CharacterSet#delete_in: 6306078.2 i/s
25
+ String#tr: 4734401.0 i/s - 1.33x slower
26
+ String#gsub: 211631.8 i/s - 29.80x slower
26
27
  ```
27
28
  ```
28
29
  Removing whitespace, emoji and umlauts
29
30
 
30
- CharacterSet#delete_in: 1712208.6 i/s
31
- String#gsub: 278508.8 i/s - 6.15x slower
31
+ CharacterSet#delete_in: 5984149.6 i/s
32
+ String#tr: 363643.1 i/s - 16.46x slower
33
+ String#gsub: 317201.7 i/s - 18.87x slower
32
34
  ```
33
35
  ```
34
36
  Removing non-whitespace
35
37
 
36
- CharacterSet#keep_in: 2760158.1 i/s
37
- String#gsub: 232797.7 i/s - 11.86x slower
38
+ CharacterSet#keep_in: 7650925.6 i/s
39
+ String#gsub: 207374.6 i/s - 36.89x slower
40
+ String#tr: 12.3 i/s - 619745.60x slower
38
41
  ```
39
42
  ```
40
- Extracting emoji
43
+ Keeping only emoji
41
44
 
42
- CharacterSet#keep_in: 1775758.8 i/s
43
- String#gsub: 217649.9 i/s - 8.16x slower
45
+ CharacterSet#keep_in: 7272940.1 i/s
46
+ String#gsub: 177993.8 i/s - 40.86x slower
47
+ String#tr: 12.3 i/s - 590222.71x slower
44
48
  ```
45
49
  ```
46
50
  Extracting emoji to an Array
47
51
 
48
- CharacterSet#scan: 2579030.8 i/s
49
- String#scan: 545107.0 i/s - 4.73x slower
52
+ CharacterSet#scan: 2978285.0 i/s
53
+ String#scan: 865793.8 i/s - 3.44x slower
50
54
  ```
51
55
  ```
52
56
  Detecting whitespace
53
57
 
54
- CharacterSet#used_by?: 13847689.0 i/s
55
- Regexp#match?: 7533275.2 i/s - 1.84x slower
58
+ CharacterSet#used_by?: 17292338.4 i/s
59
+ Regexp#match?: 11705563.9 i/s - 1.48x slower
56
60
  ```
57
61
  ```
58
62
  Detecting emoji in a large string
59
63
 
60
- CharacterSet#used_by?: 246527.7 i/s
61
- Regexp#match?: 92956.5 i/s - 2.65x slower
64
+ CharacterSet#used_by?: 340444.1 i/s
65
+ Regexp#match?: 180549.8 i/s - 1.89x slower
62
66
  ```
63
67
  ```
64
68
  Adding entries
65
69
 
66
- CharacterSet#add: 3102081.7 i/s
67
- SortedSet#add: 1897464.8 i/s - 1.63x slower
70
+ CharacterSet#add: 4951781.4 i/s
71
+ SortedSet#add: 1019637.9 i/s - 4.86x slower
68
72
  ```
69
73
  ```
70
74
  Removing entries
71
75
 
72
- CharacterSet#delete: 3240924.1 i/s
73
- SortedSet#delete: 2887493.9 i/s - 1.12x slower
76
+ CharacterSet#delete: 5006337.6 i/s
77
+ SortedSet#delete: 3922752.2 i/s - same-ish
74
78
  ```
75
79
  ```
76
80
  Merging entries
77
81
 
78
- CharacterSet#merge: 536.8 i/s
79
- SortedSet#merge: 12.5 i/s - 42.78x slower
82
+ CharacterSet#merge: 661.8 i/s
83
+ SortedSet#merge: 3.9 i/s - 167.82x slower
80
84
  ```
81
85
  ```
82
86
  Getting the min and max
83
87
 
84
- CharacterSet#minmax: 4111960.8 i/s
85
- SortedSet#minmax: 756.4 i/s - 5436.39x slower
88
+ CharacterSet#minmax: 1212462.2 i/s
89
+ SortedSet#minmax: 844.4 i/s - 1435.93x slower
86
90
  ```
data/CHANGELOG.md CHANGED
@@ -4,7 +4,56 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## UNRELEASED
7
+ ## [1.6.0] - 2022-02-16
8
+
9
+ ### Added
10
+
11
+ - `::of` now supports both `String` and `Regexp` arguments
12
+
13
+ ### Fixed
14
+
15
+ - fixed segfault during `String` manipulation on Ruby 3.2.0-dev
16
+ - improved performance for `String` manipulation
17
+ - allow usage in Ractors
18
+ - predefined sets must be pre-initialized for this, though
19
+ - e.g. `CharacterSet.ascii`, `keep_character_set(:ascii)` etc.
20
+ - call them once in the main Ractor to trigger initialization
21
+
22
+ ## [1.5.0] - 2021-12-05
23
+
24
+ ### Added
25
+
26
+ - new codepoints for `::assigned` and `::emoji` predefined sets, as in Ruby 3.1.0
27
+ - latest unicode case-folding data (for `#case_insensitive`)
28
+ - support for passing any Enumerable to `#disjoint?`, `#intersect?`
29
+ - this matches recent broadening of these methods in `ruby/set`
30
+ - new instance method `#secure_token` (see README)
31
+ - class method `::of` now accepts more than one `String`
32
+ - `CharacterSet::ExpressionConverter` can now build output of any Set-like class
33
+
34
+ ### Fixed
35
+
36
+ - `CharacterSet::Pure::of_expression` now returns a `CharacterSet::Pure`
37
+ - it used to return a regular `CharacterSet`
38
+
39
+ ## [1.4.1] - 2020-01-10
40
+
41
+ ### Fixed
42
+ - multiple fixes for Ruby 3
43
+ - fixed segfault for some `String` manipulation cases
44
+ - added `sorted_set` as dependency, so `CharacterSet::Pure` (non-C fallback) works
45
+ - fixed error when parsing a `Regexp` with an empty intersection (e.g. `/[a&&]/`)
46
+
47
+ ## [1.4.0] - 2019-06-07
48
+
49
+ ### Added
50
+ - `#to_s_with_surrogate_ranges` / `Writer::write_surrogate_ranges`
51
+ - allows for much shorter astral plane representations e.g. in JavaScript
52
+ - thanks to https://github.com/singpolyma for the suggestion and groundwork (#1)
53
+ - improved performance for `#to_s` / `Writer` by avoiding bugged `Range#minmax`
54
+
55
+ ### Fixed
56
+ - '/' is now escaped by default when stringifying so as to work with //-regexp syntax
8
57
 
9
58
  ## [1.3.0] - 2019-04-26
10
59
 
data/Gemfile CHANGED
@@ -4,3 +4,17 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in character_set.gemspec
6
6
  gemspec
7
+
8
+ gem 'benchmark-ips', '~> 2.7'
9
+ gem 'get_process_mem', '~> 0.2.3'
10
+ gem 'rake', '~> 13.0'
11
+ gem 'rake-compiler', '~> 1.1'
12
+ gem 'range_compressor', '~> 1.0'
13
+ gem 'regexp_parser', '~> 2.1'
14
+ gem 'regexp_property_values', '~> 1.0'
15
+ gem 'rspec', '~> 3.8'
16
+ if RUBY_VERSION.to_f >= 2.7
17
+ gem 'codecov', '~> 0.2.12'
18
+ gem 'gouteur', '~> 1.0.0'
19
+ gem 'rubocop', '~> 1.8'
20
+ end
data/README.md CHANGED
@@ -1,18 +1,21 @@
1
1
  # CharacterSet
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/character_set.svg)](http://badge.fury.io/rb/character_set)
4
- [![Build Status](https://travis-ci.org/jaynetics/character_set.svg?branch=master)](https://travis-ci.org/jaynetics/character_set)
4
+ [![Build Status](https://github.com/jaynetics/character_set/workflows/tests/badge.svg)](https://github.com/jaynetics/character_set/actions)
5
+ [![Build Status](https://github.com/jaynetics/character_set/workflows/gouteur/badge.svg)](https://github.com/jaynetics/character_set/actions)
5
6
  [![codecov](https://codecov.io/gh/jaynetics/character_set/branch/master/graph/badge.svg)](https://codecov.io/gh/jaynetics/character_set)
6
7
 
7
- This is a C-extended Ruby gem to work with sets of Unicode codepoints. It can read and write these sets in various formats and implements the stdlib `Set` interface for them.
8
+ This is a C-extended Ruby gem to work with sets of Unicode codepoints.
8
9
 
9
- It also offers an alternate paradigm of `String` processing which grants much better performance than `Regexp` and `String` methods from the stdlib where applicable (see [benchmarks](./BENCHMARK.md)).
10
+ It can [read](#parseinitialize) and [write](#write) sets of codepoints in various formats and it implements the stdlib `Set` interface for them.
11
+
12
+ It also offers a [way of scrubbing and scanning characters in Strings](#interact-with-strings) that is more semantic and consistently offers better performance than `Regexp` and `String` methods from the stdlib for this (see [benchmarks](./BENCHMARK.md)).
10
13
 
11
14
  Many parts can be used independently, e.g.:
12
15
  - `CharacterSet::Character`
16
+ - `CharacterSet::ExpressionConverter`
13
17
  - `CharacterSet::Parser`
14
18
  - `CharacterSet::Writer`
15
- - [`RangeCompressor`](https://github.com/jaynetics/range_compressor)
16
19
 
17
20
  ## Usage
18
21
 
@@ -40,9 +43,10 @@ CharacterSet.parse('[a-c]')
40
43
  CharacterSet.parse('\U00000061-\U00000063')
41
44
  ```
42
45
 
43
- If the gems [`regexp_parser`](https://github.com/ammar/regexp_parser) and [`regexp_property_values`](https://github.com/jaynetics/regexp_property_values) are installed, `::of_regexp` and `::of_property` can also be used. `::of_regexp` can handle intersections, negations, and set nesting.
46
+ If the gems [`regexp_parser`](https://github.com/ammar/regexp_parser) and [`regexp_property_values`](https://github.com/jaynetics/regexp_property_values) are installed, `Regexp` and unicode property names can also be read. Regexp intersections, negations, and set nesting are covered, but the `i`-flag is ignored; call `#case_insensitive` on the result if needed.
44
47
 
45
48
  ```ruby
49
+ CharacterSet.of(/./) # => #<CharacterSet (size: 1112064)>
46
50
  CharacterSet.of_property('Thai') # => #<CharacterSet (size: 86)>
47
51
 
48
52
  require 'character_set/core_ext/regexp_ext'
@@ -143,6 +147,7 @@ CharacterSet['1', 'A'].case_insensitive # => CharacterSet['1', 'A', 'a']
143
147
  ```
144
148
 
145
149
  ### Write
150
+
146
151
  ```ruby
147
152
  set = CharacterSet['a', 'b', 'c', 'j', '-']
148
153
 
@@ -167,11 +172,32 @@ set.to_s(escape_all: true) { |c| "<#{c.hex}>" } # => "<61>-<63><258><1F929>"
167
172
  # disable abbreviation (grouping of codepoints in ranges)
168
173
  set.to_s(abbreviate: false) # => "abc\u0258\u{1F929}"
169
174
 
170
- # for full js regex compatibility in case of astral members:
171
- set.to_s_with_surrogate_alternation # => '(?:[a-c\u0258]|\ud83e\udd29)'
175
+ # astral members require some trickery if we want to target environments
176
+ # that are based on UTF-16 or "UCS-2 with surrogates", such as JavaScript.
177
+ set = CharacterSet['a', 'b', '🤩', '🤪', '🤫']
178
+
179
+ # Use #to_s_with_surrogate_ranges e.g. for JavaScript:
180
+ set.to_s_with_surrogate_ranges
181
+ # => '(?:[ab]|\uD83E[\uDD29-\uDD2B])'
182
+
183
+ # Or use #to_s_with_surrogate_alternation if such surrogate set pairs
184
+ # don't work in your target environment:
185
+ set.to_s_with_surrogate_alternation
186
+ # => '(?:[ab]|\uD83E\uDD29|\uD83E\uDD2A|\uD83E\uDD2B)'
187
+ ```
188
+
189
+ ### Other features
190
+
191
+ #### Secure tokens
192
+
193
+ Generate secure random strings of characters from a set:
194
+
195
+ ```ruby
196
+ CharacterSet.new('a'..'z').secure_token(8) # => "ugwpujmt"
197
+ CharacterSet.crypt.secure_token # => "8.1w7aBT737/pMfcMoO4y2y8/=0xtmo:"
172
198
  ```
173
199
 
174
- ### Unicode plane methods
200
+ #### Unicode planes
175
201
 
176
202
  There are some methods to check for planes and to handle ASCII, [BMP](https://en.wikipedia.org/wiki/Plane_%28Unicode%29#Basic_Multilingual_Plane) and astral parts:
177
203
  ```Ruby
@@ -188,6 +214,6 @@ CharacterSet['a', 'ü', '🤩'].member_in_plane?(7) # => false
188
214
  CharacterSet::Character.new('a').plane # => 0
189
215
  ```
190
216
 
191
- ### Contributions
217
+ ## Contributions
192
218
 
193
219
  Feel free to send suggestions, point out issues, or submit pull requests.
data/Rakefile CHANGED
@@ -126,7 +126,7 @@ task :sync_predefined_sets do
126
126
  %w[assigned emoji whitespace].each do |prop|
127
127
  require 'regexp_property_values'
128
128
  ranges = RegexpPropertyValues[prop].matched_ranges
129
- str = ranges.map { |r| r.minmax.map { |n| n.to_s(16) }.join(',').upcase + "\n" }.join
129
+ str = ranges.map { |r| "#{r.min.to_s(16)},#{r.max.to_s(16)}\n" }.join.upcase
130
130
  File.write("./lib/character_set/predefined_sets/#{prop}.cps", str, mode: 'w')
131
131
  end
132
132
  end
@@ -147,8 +147,11 @@ namespace :benchmark do
147
147
  f.puts "Results of `rake:benchmark` on #{RUBY_DESCRIPTION}", ''
148
148
 
149
149
  $store_comparison_results.each do |caption, result|
150
- f.puts '```', caption, '',
151
- result.strip.gsub(/(same-ish).*$/, '\1').lines[1..-1], '```'
150
+ f.puts '```',
151
+ caption,
152
+ '',
153
+ result.strip.gsub(/ \(±[^)]+\) /, '').gsub(/(same-ish).*$/, '\1').lines[1..-1],
154
+ '```'
152
155
  end
153
156
  end
154
157
  end
@@ -2,24 +2,28 @@ require_relative './shared'
2
2
 
3
3
  str = 'Lorem ipsum et dolorem'
4
4
  rx = /\s/
5
+ trt = "\t\n\v\f\r\s"
5
6
  cs = CharacterSet.whitespace
6
7
 
7
8
  benchmark(
8
- caption: 'Removing whitespace',
9
+ caption: 'Removing ASCII whitespace',
9
10
  cases: {
10
11
  'String#gsub' => -> { str.gsub(rx, '') },
12
+ 'String#tr' => -> { str.tr(trt, '') },
11
13
  'CharacterSet#delete_in' => -> { cs.delete_in(str) },
12
14
  }
13
15
  )
14
16
 
15
17
  str = 'Lörem ipsüm ⛷ et dölörem'
16
18
  rx = /[\s\p{emoji}äüö]/
19
+ trt = "\t\n\v\f\r\s😀-🙏äüö"
17
20
  cs = CharacterSet.whitespace + CharacterSet.emoji + CharacterSet['ä', 'ö', 'ü']
18
21
 
19
22
  benchmark(
20
23
  caption: 'Removing whitespace, emoji and umlauts',
21
24
  cases: {
22
25
  'String#gsub' => -> { str.gsub(rx, '') },
26
+ 'String#tr' => -> { str.tr(trt, '') },
23
27
  'CharacterSet#delete_in' => -> { cs.delete_in(str) },
24
28
  }
25
29
  )
@@ -2,24 +2,28 @@ require_relative './shared'
2
2
 
3
3
  str = 'Lorem ipsum et dolorem'
4
4
  rx = /\S/
5
+ trt = "\u{0080}-\u{10FFFF}" # approximation
5
6
  cs = CharacterSet.whitespace
6
7
 
7
8
  benchmark(
8
9
  caption: 'Removing non-whitespace',
9
10
  cases: {
10
11
  'String#gsub' => -> { str.gsub(rx, '') },
12
+ 'String#tr' => -> { str.tr(trt, '') },
11
13
  'CharacterSet#keep_in' => -> { cs.keep_in(str) },
12
14
  }
13
15
  )
14
16
 
15
17
  str = 'Lorem ipsum ⛷ et dolorem'
16
18
  rx = /\p{^emoji}/
19
+ trt = "\u0000-\u{1F599}\u{1F650}-\u{10FFFF}"
17
20
  cs = CharacterSet.emoji
18
21
 
19
22
  benchmark(
20
- caption: 'Extracting emoji',
23
+ caption: 'Keeping only emoji',
21
24
  cases: {
22
25
  'String#gsub' => -> { str.gsub(rx, '') },
26
+ 'String#tr' => -> { str.tr(trt, '') },
23
27
  'CharacterSet#keep_in' => -> { cs.keep_in(str) },
24
28
  }
25
29
  )
data/benchmarks/shared.rb CHANGED
@@ -3,7 +3,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require 'benchmark/ips'
5
5
  require 'character_set'
6
- require 'set'
6
+ if RUBY_VERSION.to_f >= 3.0 && !RUBY_PLATFORM[/java/i]
7
+ require 'sorted_set'
8
+ else
9
+ require 'set'
10
+ end
7
11
 
8
12
  def benchmark(caption: nil, cases: {})
9
13
  puts caption
@@ -22,13 +22,10 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.required_ruby_version = '>= 2.1.0'
24
24
 
25
- s.add_development_dependency 'benchmark-ips', '~> 2.7'
26
- s.add_development_dependency 'codecov', '~> 0.1'
27
- s.add_development_dependency 'get_process_mem', '~> 0.2.3'
28
- s.add_development_dependency 'rake', '~> 12.0'
29
- s.add_development_dependency 'rake-compiler', '~> 1.0'
30
- s.add_development_dependency 'range_compressor', '~> 1.0'
31
- s.add_development_dependency 'regexp_parser', '~> 1.3'
32
- s.add_development_dependency 'regexp_property_values', '~> 0.3.5'
33
- s.add_development_dependency 'rspec', '~> 3.8'
25
+ # SortedSet, needed for RubyFallback, was moved to a gem in Ruby 3.
26
+ # This dependency is only used if the C extension is unavailable.
27
+ # JRuby has it in the stdlib.
28
+ if RUBY_VERSION.to_f >= 3.0 && !RUBY_PLATFORM[/java/i]
29
+ s.add_dependency 'sorted_set', '~> 1.0'
30
+ end
34
31
  end