[#103241] [Ruby master Bug#17777] 2.6.7 fails to build on macOS: implicit declaration of function 'rb_native_mutex_destroy' is invalid in C99 — eregontp@...
Issue #17777 has been reported by Eregon (Benoit Daloze).
17 messages
2021/04/05
[#103305] [Ruby master Feature#17785] Allow named parameters to be keywords — marcandre-ruby-core@...
Issue #17785 has been reported by marcandre (Marc-Andre Lafortune).
21 messages
2021/04/08
[#103342] [Ruby master Feature#17790] Have a way to clear a String without resetting its capacity — jean.boussier@...
Issue #17790 has been reported by byroot (Jean Boussier).
14 messages
2021/04/09
[#103388] [ANN] Multi-factor Authentication of bugs.ruby-lang.org — SHIBATA Hiroshi <hsbt@...>
Hello,
5 messages
2021/04/12
[#103414] Re: [ANN] Multi-factor Authentication of bugs.ruby-lang.org
— Martin J. Dürst <duerst@...>
2021/04/13
Is there a way to use this multi-factor authentication for (like me)
[#103547] List of CI sites to check — Martin J. Dürst <duerst@...>
Hello everybody,
4 messages
2021/04/22
[#103596] [Ruby master Feature#17830] Add Integer#previous and Integer#prev — rafasoaresms@...
Issue #17830 has been reported by rafasoares (Rafael Soares).
9 messages
2021/04/26
[ruby-core:103176] [Ruby master Feature#17771] String#start_with? should not construct MatchData or set $~
From:
eregontp@...
Date:
2021-04-02 10:28:02 UTC
List:
ruby-core #103176
Issue #17771 has been updated by Eregon (Benoit Daloze).
I don't think there is a rule that predicate methods only return a boolean and never set `$~`.
It is the case for `String#match` vs `String#match?`, but it doesn't mean it holds for other Regexp methods.
I see it a bit like the use of `!`, which in the core library is generally only used if there is also a non-`!` variant (e.g., `Array#delete`).
`String#start_with?` enables to match a regexp without the need to manually build another regexp like `/\A#{regexp}/` (from the user point of view, there might be internal caching depending on the regexp engine), so I think that is a valid use case for using `start_with?` and accessing the MatchData after.
StringScanner has a similar functionality for matching a regexp from the start, as if there was a `\A`, but does not expose `$~` directly:
`ruby -rstrscan -e 's = StringScanner.new("test string"); s.scan(/(\w)\w+/); p s[1]'` => `"t"`.
That said, I'm not against no longer setting $~ for String#start_with?, but I do worry about the compatibility issue here, especially since it might be quite hard to debug why $~ is suddenly `nil` or the previous MatchData in the Ruby version changing this behavior.
----------------------------------------
Feature #17771: String#start_with? should not construct MatchData or set $~
https://bugs.ruby-lang.org/issues/17771#change-91251
* Author: headius (Charles Nutter)
* Status: Open
* Priority: Normal
----------------------------------------
I am working on making $~ more thread-safe in JRuby and came across this unexpected behavior:
```ruby
$ rvm ruby-3.0 do ruby -e '"foo".start_with?(/foo/); p $~'
#<MatchData "foo">
```
The `start_with?` method was added 11 years ago in https://bugs.ruby-lang.org/issues/3388 but I do not think the set of $~ was an intended feature. The `start_with?` method could be much faster and more thread-safe if it did not use the frame-local backref slot and did not allocate a MatchData.
Compare with `match?` which was added specifically (without MatchData or backref setting) to provide a fast way to check if a Regexp matches.
I propose that `start_with?` stop constructing MatchData, stop setting backref, and provide only its boolean result in the same way as `match?`.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>