summaryrefslogtreecommitdiff
path: root/string.c
Commit message (Collapse)AuthorAgeFilesLines
* add static modifier for rb_str_ord funcS-H-GAMELINKS2020-05-271-1/+1
|
* Fix typos [ci skip]Kazuhiro NISHIYAMA2020-05-171-5/+5
|
* [ci skip] Enhanced rdoc for String.new (#3067)Burdette Lamar2020-05-151-15/+88
| | | | | | | * Per @nobu review * Enhanced rdoc for String.new * Respond to review
* Optimize String#splitNobuyoshi Nakada2020-05-121-26/+52
| | | | | | | | | | | | | | | | | | Optimized `String#split` with `/ /` (single space regexp) as simple string splitting. [ruby-core:98272] | |compare-ruby|built-ruby| |:--------------|-----------:|---------:| |re_space-1 | 432.786k| 1.539M| | | -| 3.56x| |re_space-10 | 76.231k| 191.547k| | | -| 2.51x| |re_space-100 | 8.152k| 19.557k| | | -| 2.40x| |re_space-1000 | 837.405| 2.022k| | | -| 2.41x| ruby-core:98272: https://bugs.ruby-lang.org/issues/15771#change-85511
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* remove unused rb_str_clear define (#3059)S.H2020-04-251-2/+0
|
* Use UNREACHABLE_RETURN for non-void functionNobuyoshi Nakada2020-04-161-2/+1
|
* Add {Regexp,String}#match with block to call-seq [ci skip]Kazuhiro NISHIYAMA2020-04-141-2/+2
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-1/+1
| | | Split ruby.h
* Warn non-nil `$/` [Feature #14240]Nobuyoshi Nakada2020-02-231-0/+15
|
* Get rid of warnings/exceptions at cleanupNobuyoshi Nakada2020-02-131-0/+1
| | | | | | | | After the encoding index instance variable is removed when all instance variables are removed in `obj_free`, then `rb_str_free` causes uninitialized instance variable warning and nil-to-integer conversion exception. Both cases result in object allocation during GC, and crashes.
* Copy non-inlined encoding indexNobuyoshi Nakada2020-02-121-0/+6
|
* Make temporary lock string encoding freeNobuyoshi Nakada2020-02-121-2/+9
| | | | | As a temporary lock string is hidden, it can not have instance variables, including non-inlined encoding index.
* Improve `String#slice!` performanceNobuyoshi Nakada2020-01-311-15/+69
| | | | | | | | | | | | | | Instead of searching twice to extract and to delete, extract and delete the found position at the first search. This makes faster nearly twice, for regexps and strings. | |compare-ruby|built-ruby| |:-------------|-----------:|---------:| |regexp-short | 2.143M| 3.918M| |regexp-long | 105.162k| 205.410k| |string-short | 3.789M| 7.964M| |string-long | 1.301M| 2.457M|
* Make `empty_string` a fake stringNobuyoshi Nakada2020-01-311-9/+9
|
* Avoid allocating a temporary empty string in String#slice!Jean Boussier2020-01-311-3/+8
|
* Added rb_warn_deprecated_to_removeNobuyoshi Nakada2020-01-231-2/+2
| | | | | Warn the deprecation and future removal, with obeying the warning flag.
* Make taint warnings non-verbose instead of verboseJeremy Evans2020-01-221-2/+2
|
* Fix `String#partition`Nobuyoshi Nakada2020-01-161-1/+0
| | | | | Split with the matched part when the separator matches the empty part at the beginning. [Bug #11014]
* [DOC] Improve docs for String#matchMarcus Stollsteimer2020-01-081-8/+8
| | | | Fix invalid code to make it syntax highlighted; other small fixes.
* Improve docs for String#=~Marcus Stollsteimer2020-01-081-9/+14
| | | | | | | | Move existing example to the corresponding paragraph and add an example for `string =~ regexp` vs. `regexp =~ string`; avoid using the receiver's identifier from the call-seq because it does not appear in rendered HTML docs; mention deprecation of Object#=~; fix some markup and typos.
* decouple internal.h headers卜部昌平2019-12-261-16/+31
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* Refined the warning message for $, and $;Nobuyoshi Nakada2019-12-201-1/+1
| | | | [Bug #16438]
* Added Symbol#start_with? and Symbol#end_with? method. [Feature #16348]NARUSE, Yui2019-11-281-0/+43
|
* delete unused codes卜部昌平2019-11-181-2/+0
| | | | Suppress compiler warnings.
* rb_tainted_str_new_with_enc is no longer usedNobuyoshi Nakada2019-11-181-7/+0
|
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-101/+19
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* delete unused functions卜部昌平2019-11-141-7/+0
| | | | | | | | | | | | Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine.
* Revert "[EXPERIMENTAL] Make Symbol#to_s return a frozen String [Feature #16150]"NARUSE, Yui2019-11-051-3/+2
| | | | This reverts commit 6ffc045a817fbdf04a6945d3c260b55b0fa1fd1e.
* Documentation improvements for Ruby corezverok2019-10-261-20/+31
| | | | | | | | | | | * Top-level `return`; * Documentation for comments syntax; * `rescue` inside blocks; * Enhance `Object#to_enum` docs; * Make `chomp:` option more obvious for `String#each_line` and `#lines`; * Enhance `Proc#>>` and `#<<` docs; * Enhance `Processs` class docs.
* Reduce the minimum string buffer size from 127 to 63 bytesLourens Naudé2019-10-111-1/+1
|
* avoid overflow in integer multiplication卜部昌平2019-10-091-1/+1
| | | | | | | This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes.
* [EXPERIMENTAL] Make Symbol#to_s return a frozen StringBenoit Daloze2019-09-261-2/+3
| | | | | | * Always the same frozen String for a given Symbol. * Avoids extra allocations whenever calling Symbol#to_s. * See [Feature #16150]
* Rename STR_IS_SHARED_M to STR_BORROWEDAlan Wu2019-09-261-6/+7
| | | | | | | Since the introduction of STR_SHARED_ROOT, the word "shared" has become very overloaded with respect to String's internal states. Use a different name for STR_IS_SHARED_M and explain its purpose.
* Tag string shared roots to fix use-after-freeAlan Wu2019-09-261-4/+16
| | | | | | | | | | | | | | The buffer deduplication codepath in rb_fstring can be used to free the buffer of shared string roots, which leads to use-after-free. Introudce a new flag to tag strings that at one point have been a shared root. Check for it in rb_fstring to avoid freeing buffers that are shared by multiple strings. This change is based on nobu's idea in [ruby-core:94838]. The included test case test for the sequence of calls to internal functions that lead to this bug. See attached ticket for Ruby level repros. [Bug #16151]
* Make Symbol#to_proc calls handle keyword argumentsJeremy Evans2019-09-051-2/+2
| | | | | | Make rb_sym_proc_call take a flag for whether a keyword argument is used, and use the new rb_funcall_with_block_kw function to pass that information.
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-1/+23
| | | | | | We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
* Fixed heap-use-after-freeNobuyoshi Nakada2019-08-151-1/+2
| | | | | | * string.c (rb_str_sub_bang): retrieves a pointer to the replacement string buffer just before using it, for the case of replacement with the receiver string itself. [Bug #16105]
* * expand tabs. [ci skip]git2019-08-151-2/+2
|
* Fold to lowercase intead of uppercase for String#casecmpJeremy Evans2019-08-141-4/+4
| | | | strcasecmp(3) and String#casecmp? both fold to lowercase.
* Update docs to use more natural EnglishAaron Patterson2019-08-121-10/+10
| | | | Just a few updates to make the English sound a bit more natural
* string.c (rb_str_sub, _gsub): improve the rdocYusuke Endoh2019-08-121-21/+58
| | | | | | | | | | | | This change: * Added an explanation about back references except \n and \k<n> (\` \& \' \+ \0) * Added an explanation about an escape (\\) * Added some rdoc references * Rephrased and clarified the reason why double escape is needed, added some examples, and moved the note to the last (because it is not specific to the method itself).
* leafify opt_plus卜部昌平2019-08-061-0/+31
| | | | | | Inspired by 346aa557b31fe96760e505d30da26eb7a846bac9 Closes: https://github.com/ruby/ruby/pull/2321
* Make opt_eq and opt_neq insns leafTakashi Kokubun2019-08-041-18/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | # Benchmark zero? ``` require 'benchmark/ips' Numeric.class_eval do def ruby_zero? self == 0 end end Benchmark.ips do |x| x.report('0.zero?') { 0.ruby_zero? } x.report('1.zero?') { 1.ruby_zero? } x.compare! end ``` ## VM No significant impact for VM. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) [x86_64-linux] 0.zero?: 21855445.5 i/s 1.zero?: 21770817.3 i/s - same-ish: difference falls within error ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) [x86_64-linux] 1.zero?: 21958912.3 i/s 0.zero?: 21881625.9 i/s - same-ish: difference falls within error ## JIT The performance improves about 1.23x. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) +JIT [x86_64-linux] 0.zero?: 36343111.6 i/s 1.zero?: 36295153.3 i/s - same-ish: difference falls within error ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) +JIT [x86_64-linux] 0.zero?: 44740467.2 i/s 1.zero?: 44363616.1 i/s - same-ish: difference falls within error # Benchmark str == str / str != str ``` # frozen_string_literal: true require 'benchmark/ips' Benchmark.ips do |x| x.report('a == a') { 'a' == 'a' } x.report('a == b') { 'a' == 'b' } x.report('a != a') { 'a' != 'a' } x.report('a != b') { 'a' != 'b' } x.compare! end ``` ## VM No significant impact for VM. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) [x86_64-linux] a == a: 27286219.0 i/s a != a: 24892389.5 i/s - 1.10x slower a == b: 23623635.8 i/s - 1.16x slower a != b: 21800958.0 i/s - 1.25x slower ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) [x86_64-linux] a == a: 27224016.2 i/s a != a: 24490109.5 i/s - 1.11x slower a == b: 23391052.4 i/s - 1.16x slower a != b: 21811321.7 i/s - 1.25x slower ## JIT The performance improves on JIT a little. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) +JIT [x86_64-linux] a == a: 42010674.7 i/s a != a: 38920311.2 i/s - same-ish: difference falls within error a == b: 32574262.2 i/s - 1.29x slower a != b: 32099790.3 i/s - 1.31x slower ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) +JIT [x86_64-linux] a == a: 46902738.8 i/s a != a: 43097258.6 i/s - 1.09x slower a == b: 35822018.4 i/s - 1.31x slower a != b: 33377257.8 i/s - 1.41x slower This is needed towards Bug#15589. Closes: https://github.com/ruby/ruby/pull/2318
* Reuse match dataNobuyoshi Nakada2019-07-281-2/+5
| | | | * string.c (rb_str_split_m): reuse occupied match data. [Bug #16024]
* Occupy match dataNobuyoshi Nakada2019-07-271-1/+3
| | | | | * string.c (rb_str_split_m): occupy match data not to be modified during yielding the block. [Bug #16024]
* string.c (str_succ): refactoringYusuke Endoh2019-07-141-3/+3
| | | | Use more communicative variable name
* string.c (str_succ): remove a unnecessary assignmentYusuke Endoh2019-07-141-1/+0
| | | | This change will suppress Coverity Scan warnings
* * expand tabs.git2019-07-141-1/+1
|