fast_regexp 0.5.0-aarch64-linux → 0.6.1-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d582628d35a655bddbc2957b25874b21ee2c7a53c3cde023c1cf7a2a7570ed2
4
- data.tar.gz: 161d29c08b3897f77248b624904fa26ddf7512ae73f74f31d845ac545d70bfea
3
+ metadata.gz: 9e8f43c5d2a9aa1903943558c35ab6a46b15df0b752c652f6442bd6a328bce7c
4
+ data.tar.gz: 666effbf46f4db06dbc5b644c88202daac203e7c167cf060cbb5d1f2e63d66a5
5
5
  SHA512:
6
- metadata.gz: d53c46c5cc47cc38d4b1b64c1c93473850ee5b9ae864538c0792a2675b9bf64496eb7328193678bff35990810be6dbe80340cd74d6dd099fedb6f4f79607a262
7
- data.tar.gz: 280a5bc0c14b490089cc6a3098bceba67bd58dfb347a526c3ee979ad11561888fdb7342a53173c7a854727d352b8ab0cf4f900740f448958e867308ee47834de
6
+ metadata.gz: 38ca3692c0b727e5003acca7e24031b73c19fd2957bfbe715dae5c5edd2065fa93ba9e665d2f6cebbc721513957c25193c5c5ca3125e6be59bbc236244fefe52
7
+ data.tar.gz: '040688216ab69d2ab613548b3dab2b798e90a776c2cff4d107ddc9f4208943b0439cb8d8124128dcb6015b81a316eae4cf8f8cc49d44bdcf5a7126c6b6216146'
data/README.md CHANGED
@@ -5,12 +5,10 @@
5
5
 
6
6
  Fast, drop-in regex for Ruby — backed by [rust/regex](https://docs.rs/regex/latest/regex/) with transparent fallback to the stdlib `::Regexp` engine for features rust/regex doesn't support (lookaround, backreferences, possessive quantifiers, etc.).
7
7
 
8
- You get rust/regex's speed and GVL-releasing matching on the common path, and a single uniform API (`Fast::Regexp`, `Fast::Regexp::MatchData`) regardless of which engine actually ran underneath.
8
+ You get rust/regex's speed on the common path, and a single uniform API (`Fast::Regexp`, `Fast::Regexp::MatchData`) regardless of which engine actually ran underneath.
9
9
 
10
10
  ## Installation
11
11
 
12
- Install [Rust](https://www.rust-lang.org/) via [rustup](https://rustup.rs/) or in any other way.
13
-
14
12
  Add as a dependency:
15
13
 
16
14
  ```ruby
@@ -21,6 +19,14 @@ gem "fast_regexp"
21
19
  gem install fast_regexp
22
20
  ```
23
21
 
22
+ Precompiled native gems are published for **arm64-darwin**, **x86_64-linux**,
23
+ and **aarch64-linux** against Ruby **3.3**, **3.4**, and **4.0** — no Rust
24
+ toolchain required on those platforms.
25
+
26
+ On any other platform/Ruby combo, Bundler/RubyGems falls back to the source
27
+ gem and compiles the extension at install time. That path needs
28
+ [Rust](https://www.rust-lang.org/) (install via [rustup](https://rustup.rs/)).
29
+
24
30
  Include in your code:
25
31
 
26
32
  ```ruby
@@ -155,6 +161,14 @@ slow.match?("foobar") # => true
155
161
  / `#stdlib` accessors. Replacement templates use rust/regex syntax (`$1`,
156
162
  `${name}`, `$$`) on both paths; the stdlib fallback translates them for you.
157
163
 
164
+ You can force a specific engine via the `backend:` kwarg:
165
+
166
+ ```ruby
167
+ Fast::Regexp.new('\w+', backend: :fast) # rust/regex only; raises on unsupported
168
+ Fast::Regexp.new(pat, backend: :stdlib) # skip rust/regex; use ::Regexp directly
169
+ Fast::Regexp.new('\w+', backend: :auto) # default — try rust, fall back on reject
170
+ ```
171
+
158
172
  > [!NOTE]
159
173
  > The fast path is byte-based (rust/regex's `regex::bytes`), so `#=~` returns
160
174
  > a *byte* offset. The stdlib fallback path returns the byte offset too, for
@@ -230,7 +244,7 @@ In-depth docs live under [`docs/`](docs/README.md), organized via the
230
244
  - **Tutorial:** [Getting started](docs/tutorials/getting-started.md)
231
245
  - **How-to:** [Migrate from stdlib `::Regexp`](docs/how-to/migrate-from-stdlib-regexp.md), [Handle unsupported syntax](docs/how-to/handle-unsupported-syntax.md)
232
246
  - **Reference:** [`Fast::Regexp`](docs/reference/fast-regexp.md), [`MatchData`](docs/reference/fast-regexp-matchdata.md), [`Set`](docs/reference/fast-regexp-set.md)
233
- - **Explainers:** [Engine fallback](docs/explainers/engine-fallback.md), [Concurrency and GVL](docs/explainers/concurrency-and-gvl.md)
247
+ - **Explainers:** [Engine fallback](docs/explainers/engine-fallback.md)
234
248
 
235
249
  ## Development
236
250
 
@@ -252,8 +266,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jetpks
252
266
  huge thanks for the original bindings and the clean magnus integration that
253
267
  made this work easy to extend. This fork rebrands the gem, reshapes the
254
268
  public API (`Fast::Regexp`, real `MatchData`, `sub`/`gsub`, `===`/`=~`,
255
- `Regexp`-constructor coercion), releases the GVL around regex execution for
256
- thread/fiber-friendly matching, and adds transparent fallback to stdlib
269
+ `Regexp`-constructor coercion), and adds transparent fallback to stdlib
257
270
  `::Regexp` for patterns rust/regex can't compile.
258
271
 
259
272
  ## License
Binary file
Binary file
Binary file
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fast
4
4
  class Regexp
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.1"
6
6
  end
7
7
  end
data/lib/fast_regexp.rb CHANGED
@@ -6,16 +6,27 @@ module Fast
6
6
  # Façade over rust/regex with a transparent fallback to stdlib `::Regexp`.
7
7
  #
8
8
  # `Fast::Regexp.new(pattern)` first tries to compile with rust/regex (fast,
9
- # GVL-releasing, byte-based). If the pattern uses features rust/regex does
10
- # not support (lookaround, backreferences, possessive quantifiers, etc.) we
11
- # fall back to `::Regexp` so consumers don't have to juggle two libraries.
9
+ # byte-based). If the pattern uses features rust/regex does not support
10
+ # (lookaround, backreferences, possessive quantifiers, etc.) we fall back
11
+ # to `::Regexp` so consumers don't have to juggle two libraries.
12
12
  class Regexp
13
+ NATIVE_EXTENSIONS = %w[.bundle .so .rb].freeze
14
+
15
+ # Precompiled native gems ship per-ABI subdirs (`fast_regexp/4.0/...`),
16
+ # the source-gem `rake compile` build lands flat (`fast_regexp/...`).
17
+ # Pick whichever exists for the current Ruby ABI, with the per-ABI path
18
+ # winning when both are present.
19
+ def self.locate_native(base, ruby_version: RUBY_VERSION)
20
+ abi = ruby_version[/\d+\.\d+/]
21
+ candidates = [File.join(base, abi, "fast_regexp"), File.join(base, "fast_regexp")]
22
+ candidates.find { |stem| NATIVE_EXTENSIONS.any? { |ext| File.exist?(stem + ext) } }
23
+ end
13
24
  end
14
25
  end
15
26
 
16
- # Load the native extension AFTER the Fast::Regexp class shell exists — the
17
- # Rust init() looks up Fast::Regexp and registers Native under it.
18
- require_relative "fast_regexp/fast_regexp"
27
+ native = Fast::Regexp.locate_native(File.expand_path("fast_regexp", __dir__))
28
+ raise LoadError, "could not locate fast_regexp native extension" unless native
29
+ require native
19
30
 
20
31
  module Fast
21
32
  class Regexp
@@ -34,6 +45,15 @@ module Fast
34
45
  allocate.tap { |re| re.send(:initialize, translated, original: pattern, **opts) }
35
46
  end
36
47
 
48
+ # Bulk-compile a symbol-keyed hash of patterns. Handy for defining a set
49
+ # of regex constants in one shot:
50
+ #
51
+ # RE = Fast::Regexp.create_many(word: '\w+', num: '\d+').freeze
52
+ # RE[:word].match("hello")
53
+ def create_many(**patterns)
54
+ patterns.transform_values { |pat| new(pat) }
55
+ end
56
+
37
57
  private
38
58
 
39
59
  def translate_regexp(regexp)
@@ -46,11 +66,17 @@ module Fast
46
66
 
47
67
  attr_reader :pattern, :backend
48
68
 
69
+ BACKENDS = %i[auto fast stdlib].freeze
70
+
49
71
  # Internal — use `Fast::Regexp.new`. `original` is the unmodified input
50
72
  # (String or ::Regexp) so we can build an accurate stdlib fallback.
51
- def initialize(pattern, original: pattern, **opts)
73
+ # `backend:` forces a specific engine: `:auto` (default) tries rust/regex
74
+ # and falls back to stdlib, `:fast` raises if rust/regex rejects the
75
+ # pattern, `:stdlib` skips rust/regex entirely.
76
+ def initialize(pattern, original: pattern, backend: :auto, **opts)
77
+ raise ArgumentError, "backend must be one of #{BACKENDS.inspect}" unless BACKENDS.include?(backend)
52
78
  @pattern = pattern
53
- @backend = compile_backend(pattern, original, opts)
79
+ @backend = compile_backend(pattern, original, backend, opts)
54
80
  end
55
81
 
56
82
  def fast? = @backend.is_a?(Native)
@@ -178,17 +204,22 @@ module Fast
178
204
  count
179
205
  end
180
206
 
181
- def compile_backend(pattern, original, opts)
207
+ def compile_backend(pattern, original, backend, opts)
208
+ return compile_stdlib(pattern, original) if backend == :stdlib
182
209
  Native._native_new(pattern, **opts)
183
210
  rescue ArgumentError => e
211
+ raise if backend == :fast
212
+ compile_stdlib(pattern, original, fallback_from: e)
213
+ end
214
+
215
+ def compile_stdlib(pattern, original, fallback_from: nil)
184
216
  return original if original.is_a?(::Regexp)
185
- begin
186
- ::Regexp.new(pattern)
187
- rescue ::RegexpError
188
- # Pattern is malformed in both engines surface the original
189
- # rust/regex error so the user sees the more detailed message.
190
- raise ArgumentError, e.message
191
- end
217
+ ::Regexp.new(pattern)
218
+ rescue ::RegexpError => e
219
+ # Pattern is malformed in both engines (auto path) — surface the
220
+ # original rust/regex error since it's typically more detailed.
221
+ # Otherwise propagate the stdlib error as-is.
222
+ raise(fallback_from ? ArgumentError.new(fallback_from.message) : e)
192
223
  end
193
224
 
194
225
  # Maps positional capture indices to names for the stdlib backend so we
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_regexp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Eric Jacobs