Граф коммитов

1224 Коммитов

Автор SHA1 Сообщение Дата
nobu 4592e15e35 string.c: remove redundant calls
* string.c (rb_str_enumerate_bytes, rb_str_enumerate_codepoints):
  do not check if a block is given twice.  RETURN_SIZED_ENUMERATOR
  includes rb_block_given_p() check which is redundant here.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-15 01:29:37 +00:00
normal bbf7495fe2 string.c: ensure String#freeze resizes internal buffer
rb_str_freeze may resize oversized buffers to save memory, so favor
it over rb_obj_freeze.  This is useful because IO methods do not
prematurely shrink buffers, as they are likely to be overwritten
with full data.

* string.c (Init_String): use rb_str_freeze for String#freeze

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-06 19:45:02 +00:00
nobu 0918c27a40 string.c: register_fstring
* string.c (register_fstring): separate registration from
  rb_fstring().

* string.c (rb_fstring_new): skip argument checks in rb_fstring().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-06 02:24:29 +00:00
normal a12fb26ff7 string.c (rb_str_justify): use RB_GC_GUARD
See doc/extension.rdoc for justification using RB_GC_GUARD instead
of volatile.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-24 07:17:44 +00:00
nobu d3199656be string.c: rb_fstring_cstr
* string.c (rb_fstring_cstr): new function to make a fstring from
  a string literal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-24 03:50:56 +00:00
normal a02a3f4649 socket: allow explicit buffer for recv and recv_nonblock
This reduces GC overhead and makes the API more consistent
with IO#read and IO#read_nonblock.

* ext/socket/basicsocket.c (bsock_recv): document outbuf
* ext/socket/unixsocket.c (unix_recvfrom): ditto
* ext/socket/init.c (rsock_strbuf, recvfrom_locktmp): new functions
  (rsock_s_recvfrom): support destination buffer as 3rd arg
  (rsock_s_recvfrom_nonblock): ditto
* string.c (rb_str_locktmp_ensure): export for internal ext
* test/socket/test_nonblock.rb: test recv_nonblock
* test/socket/test_unix.rb: test recv
  [ruby-core:69543] [Feature #11242]

Benchmark results:

             user     system      total        real
alloc    0.130000   0.280000   0.410000 (  0.420656)
extbuf   0.100000   0.220000   0.320000 (  0.318708)

-------------------8<--------------------
require 'socket'
require 'benchmark'
nr = 100000
msg = ' ' * 16384
size = msg.bytesize
buf = ' ' * size
UNIXSocket.pair(:DGRAM) do |a, b|
  Benchmark.bmbm do |x|
    x.report('alloc') do
      nr.times do
        b.send(msg, 0)
        a.recv(size, 0)
      end
    end

    x.report('extbuf') do
      nr.times do
        b.send(msg, 0)
        a.recv(size, 0, buf)
      end
    end
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-15 20:02:43 +00:00
hsbt 5ffb21ebbd * string.c: added documentation for character sequence \' with String#sub
[Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by @shishir127

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-16 12:41:29 +00:00
nobu 80e0ef3a81 range.c: move String specific code
* range.c (range_include): call rb_str_include_range_p on String.

* string.c (str_upto_each): extract from rb_str_upto.

* string.c (rb_str_include_range_p): move String specific code
  from Range#include? in range.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-15 12:39:56 +00:00
nobu d70228d105 string.c: all_digits_p
* string.c (all_digits_p): extract duplicate code from
  rb_str_upto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-15 09:06:25 +00:00
glass f64ac5d4cd * string.c (rb_str_crypt): Raise ArgumentError when
string passed to String#crypt contains null.
  the patch is from jrusnack <jrusnack at redhat.com>.
  [Bug #10988] [fix GH-853]

* test/ruby/test_string.rb: test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-10 02:49:01 +00:00
nobu 2b0a6f47ac revert r50336
* string.c (str_buf_cat): expand later so that the buffer can be
  larger for further use.  [Bug #11080] [Bug #11080]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-25 05:26:22 +00:00
nobu b3626b3ee7 string.c: expand heap
* string.c (str_buf_cat): expand the heap buffer at making
  str independent, not only just copying.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-17 03:26:21 +00:00
nobu 26fa27fe12 string.c: clear NOFREE flag at embedding
* string.c (STR_SET_EMBED): clear NOFREE flag at embedding as
  embedded strings no longer refer static strings.
  [ruby-core:68436] [Bug #10942]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-17 02:58:37 +00:00
nobu 8c0b2a2860 string.c: check before modify
* string.c (rb_str_setbyte): check the argument first not to
  discard shared string and code range unnecessarily until
  actually changing the contents.  pointed out by headius.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-04 02:30:26 +00:00
ko1 89a603d2e6 * string.c: add a comment about RSTRING_FSTR.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-18 03:08:09 +00:00
ko1 1e98a25e9f * string.c: introduce STR_FAKESTR to show string is FAKESTR or not.
* string.c (STR_SET_SHARED): ignore FAKESTR because only Ruby objects
  can use write barrier.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-17 20:38:02 +00:00
nobu 4c0106ead6 string.c: smart chomp
* string.c (chompped_length): enable smart chomp for all non-dummy
  encoding strings, not only default_rs.
  [ruby-core:68258] [Bug #10893]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-24 00:47:12 +00:00
nobu 4f3217e326 string.c: raise a RegexpError
* string.c (get_pat_quoted): simply raise a RegexpError, TypeError
  is never raised.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-23 06:26:59 +00:00
nobu a10fdc9270 string.c: proper exception
* string.c (rb_str_split_m): raise ArgumentError at broken string
  not RegexpError, as Regexp is not involved in.
  [ruby-core:68229] [Bug #10886]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-23 06:26:42 +00:00
nobu 16294913f7 use rb_funcallv
* use rb_funcallv() for no arguments call instead of variadic
  rb_funcall().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-16 04:08:52 +00:00
mame 2270365bde * string.c (str_discard): does not free for STR_NOFREE string.
[Bug #10853][ruby-core:68110]

* bootstraptest/test_string.rb: test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-13 13:06:58 +00:00
marcandre af574c63b5 * string.c: [DOC] Specify to_s on subclasses [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-29 15:56:58 +00:00
nobu 44bf6684fd string.c: term fill
* string.c (str_buf_cat): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-26 03:43:20 +00:00
nobu c0d0dd91e5 string.c: use local variables
* string.c (str_buf_cat): use local variables instead of repeating
  macros.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-26 03:43:08 +00:00
nobu 34d4105556 string.c: consider widechar
* string.c (str_make_independent_expand): consider wide char
  encoding.  [Fix GH-821]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-26 02:39:00 +00:00
nobu 622f3f14b6 string.c: terminate when embedded
* string.c (str_make_independent_expand): terminate String when
  moved from heap to embedded.  [Fix GH-821].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-26 02:37:51 +00:00
ayumin e717341ea6 * string.c: improve docs for String#<=>. [ruby-core:65399][Feature #10322]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-04 04:10:31 +00:00
ayumin 6abaf76463 * string.c: improve docs for String#strip and variations. [ruby-core:66081][Bug #10476]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-04 03:37:10 +00:00
nobu 020fcc95fe string.c: fix coderange for non-endianness string
* string.c (rb_enc_str_coderange): dummy wchar, non-endianness
  encoding string cannot be ascii only.
  [ruby-core:66835] [Bug #10598]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-15 07:19:25 +00:00
nobu 4d3677e14b string.c: reduce intermediate string
* string.c (rb_str_succ_bang): get rid of making intermediate
  string object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 07:23:18 +00:00
nobu 3b8c100418 string.c: term fill
* string.c (rb_str_succ): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 02:24:51 +00:00
nobu b96ff20fef string.c: use local variables
* string.c (rb_str_succ): extract local variables from constant
  RSTRING_PTR and RSTRING_LEN.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 02:24:49 +00:00
nobu 01e621579a string.c: check arguments for crypt
* string.c (rb_str_crypt): check arguments more strictly.
  * crypt() is not for wide char strings
  * salt bytes should not be NUL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 01:49:20 +00:00
nobu 9cabd72f5f string.c: term fill
* string.c (rb_str_justify): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 01:32:36 +00:00
nobu 88ae402cbf string.c: term fill
* string.c (tr_trans): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 01:20:41 +00:00
nobu 5c100b57f8 string.c: term fill
* string.c (rb_str_squeeze_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-11 00:37:58 +00:00
nobu 7a77cf7133 string.c: term fill
* string.c (rb_str_delete_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 12:26:11 +00:00
nobu 117438ee7b string.c: term fill
* string.c (rb_str_sub_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 12:09:49 +00:00
nobu 9d17096309 string.c: term fill
* string.c (rb_str_splice_0): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:49:10 +00:00
nobu ed94c24944 string.c: term fill
* string.c (rb_str_chop_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:56 +00:00
nobu c77efe1144 string.c: term fill
* string.c (rb_str_chomp_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:48 +00:00
nobu 0c50d7ba15 string.c: term fill
* string.c (rb_str_times): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:43 +00:00
nobu c00aca4aa0 string.c: term fill
* string.c (rb_str_plus): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:34 +00:00
nobu b890ed926a string.c: local variables
* string.c (rb_str_plus, rb_str_splice_0): extract local
  variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:21 +00:00
nobu 516b9026fd string.c: chompped_length chomp_rs
* string.c (chompped_length, chomp_rs): extract from
  rb_str_chomp_bang to share with rb_str_chomp.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:17 +00:00
hsbt 93db27d51f * string.c: [DOC] Add missing documentation around String#chomp.
Patchby @stderr [ci skip][fix GH-780]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 11:24:46 +00:00
nobu 49b3b2d8a2 string.c: fake string is not sharing
* string.c (setup_fake_str): fake string does not share another
  string, but just should not free.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-03 05:34:10 +00:00
nobu aaed10716a intern.h: SIZED_ENUMERATOR
* include/ruby/intern.h (SIZED_ENUMERATOR): separate from
  RETURN_SIZED_ENUMERATOR.

* string.c (rb_str_enumerate_chars): get rid of calling
  rb_block_given_p() twice.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-03 03:25:12 +00:00
nobu 25bab786cb string.c: preserve encoding of global variable
* string.c (rb_str_setter): preserve encoding of global variable
  name in error message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-23 17:03:48 +00:00
akr 2b9191e557 * internal.h: Gather declarations in non-header files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-18 15:13:05 +00:00
nobu 85ba516877 string.c: escape a backslash [ci skip]
* string.c (rb_str_count): [DOC] add a backslash to escape a
  backslash itself.  [ruby-core:66321]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-16 19:11:37 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
ko1 495548ace4 * string.c (sym_equal): use rb_obj_equal().
rb_obj_equal() is specially optimized in
  opt_eq_func()@vm_insnhelper.c.
  This fix is made from this discussion:
  https://www.omniref.com/ruby/2.1.4/symbols/Symbol/%3D%3D#line=8361.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-11 01:42:01 +00:00
nobu c58962d43f string.c: no exception in QUOTE
* string.c (sym_printable): QUOTE() should not raise an exception
  even on invalid byte sequence.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-06 14:55:20 +00:00
nobu a707ab4bc8 string.c: no terminator
* string.c (rb_str_{,l,r}strip_bang): rb_str_subseq() will not
  NUL-terminate the result string, in the future, so it will not
  be needed in other cases.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-05 06:05:14 +00:00
nobu 62ede28373 string.c: reduce memory copy
* string.c (rb_str_lstrip, rb_str_strip): reduce memory copy by
  copying necessary part only.
* string.c (rb_str_strip_bang, rb_str_strip): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-05 03:13:55 +00:00
nobu 3614f8bd1c string.c: wchar terminator
* string.c (rb_str_lstrip_bang, rb_str_rstrip_bang): terminate
  wchar strings with wchar 0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-05 01:54:22 +00:00
duerst d26c49657d string.c: improved comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-26 02:24:28 +00:00
akr 0d4185f30e * Avoid undefined behaviors found by gcc -fsanitize=undefined.
gcc (Debian 4.9.1-16) 4.9.1

* string.c (rb_str_sum): Avoid undefined behavior.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-17 09:49:28 +00:00
nobu 5617e31771 symbol.c: rename rb_str_dynamic_intern
* iseq.c, marshal.c, string.c: use rb_str_intern instead of
  rb_str_dynamic_intern.
* symbol.c (rb_str_intern): rename rb_str_dynamic_intern.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-14 07:23:01 +00:00
normal 58a73d96b4 string.c (rb_str_intern): remove unnecessary RB_GC_GUARD
Incorrectly placed, and no longer needed since r25351

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-11 06:02:42 +00:00
nobu ef08f00541 string.c: fix NOFREE
* string.c (str_make_independent_expand): drop NOFREE flag after
  reallocation, static buffer is not pointed anymore.
  [ruby-core:65317] [Bug #10304]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-29 13:54:37 +00:00
nobu abac848564 string.c: rb_str_new_static
* string.c (rb_str_new_static): create string object with static
  buffer.  incorporated from mruby.

* string.c (rb_{usascii,utf8,enc}_str_new_static): ditto with
  encodings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-19 05:53:00 +00:00
nobu 1495c2f8e9 string.c: UTF-8 string function
* string.c (rb_utf8_str_new, rb_utf8_str_new_cstr): make UTF-8
  string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-18 14:51:08 +00:00
normal a4a2b9be7a string.c (Init_frozen_strings): use st_init_table_with_size
All symbols have an fstring entry, and we initialize symbol tables
with 1000 bins.  This reduces resizes during startup.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-11 21:57:34 +00:00
naruse a8ec4b2cf2 * string.c (sym_find): remove Symbol.find because we have Symbol GC now.
https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20140904Japan
  If you still want this, request again on Redmine. [Feature #7854]
  https://bugs.ruby-lang.org/issues/7854

* ext/-test-/symbol/init.c (sym_find): moved from string.c for tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-11 21:22:52 +00:00
normal 343f8b02a1 string.c: remove vm_core.h dependency [ruby-core:64627]
* string.c: revert part of r47311, add rb_vm_fstring_table(),
  remove vm_core.h dependency. [ruby-core:64627]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-29 07:22:23 +00:00
normal a1e95636ac string.c: move frozen_strings table to rb_vm_t
Cleanup in case MVM development proceeds.

* string.c: remove static frozen_strings
* string.c (Init_frozen_strings): new function
* string.c (rb_fstring): remove check for frozen strings,
  use per-VM table
* string.c (rb_str_free): use per-VM table
* string.c (Init_String): use per-VM table
* vm_core.h (rb_vm_t): add frozen_strings table
* internal.h (Init_frozen_strings): new function prototype
* eval.c (ruby_setup): call Init_frozen_strings
  [Feature #10182]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-29 06:30:03 +00:00
ko1 7bfaa467ce * string.c (rb_fstring): fix condition (easy to cause infinite loop!).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-22 11:24:38 +00:00
ko1 32dcb81d58 * string.c (rb_fstring, fstr_update_callback): simply delete garbage
key first.
  Garbage keys can be swept by lazy sweeping invoked by creating new
  fstring.  So that simply do:
  (1) delete garbage key and return `fstr_update_callback' immediately
  (2) try again `fstr_update_callback()' to create a new fstr.
  This bug can be cause memory corruption, reported by
  http://u64.rubyci.org/~chkbuild/ruby-trunk/log/20140821T220302Z.fail.html.gz



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-22 11:16:56 +00:00
nobu 3636e08858 string.c: rb_setup_fake_str
* string.c (rb_setup_fake_str): setup fake string from C pointer,
  length, and encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-16 03:36:47 +00:00
ko1 6f7366c206 * string.c (setup_fake_str): fake strings should not set class by
RBASIC_SET_CLASS() because it insert write barriers to fake
  (non-RVALUE) structure.
  It can cause unexpected behaviour.
  Ruby 2.1 also have a same problem (setup_fake_str() in parse.y).
* symbol.c (setup_fake_str): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-15 10:37:42 +00:00
nobu 6db9db48ad string.c: rb_to_symbol
* string.c (rb_to_symbol): new function to convert an object to a
  symbol.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-30 12:36:31 +00:00
nobu 98b2401077 string.c: simplify
* string.c (rb_str_count): move code for the first argument
  outside loop for the rest, as it is executed only once.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-22 05:22:32 +00:00
nobu d2d9257cd4 string.c: raise at invalid byte sequence
* string.c (rb_str_count): raise at invalid byte sequence argument
  even if single-byte optimization is effective.
  [ruby-dev:48442] [Bug #10078]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-22 04:33:38 +00:00
nobu 1a95e46cc6 string.c: fix wrong single-byte optimization
* string.c (rb_str_count): fix wrong single-byte optimization.
  7bit ascii can be a trailing byte in Shift_JIS.
  [ruby-dev:48442] [Bug #10078]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-22 03:56:26 +00:00
ktsj ef809762e5 * string.c: [DOC] teach rdoc symbol.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-19 04:22:36 +00:00
ko1 76a929a7fc * parse.y: change Symbol <-> ID relationship to avoid
exposing IDs from collectable symbols.
  [Bug #10014]
  Now, rb_check_id() returns 0 if corresponding symbol is
  pinned dynamic symbol.
  There is remaining intern_cstr_without_pindown(), it can return
  IDs from collectable symbols. We must be careful to use it
  (only used in parse.y).  I think it should be removed if
  it does not have impact for performance.
* parse.y:
  add:
  * STATIC_SYM2ID()
  * STATIC_ID2SYM()
  rename:
  * rb_pin_dynamic_symbol() -> dsymbol_pindown()
* internal.h:
  remove:
  * rb_check_id_without_pindown()
  * rb_sym2id_without_pindown()
  add:
  * rb_check_symbol()
  * rb_check_symbol_cstr()
* load.c: use rb_check_id() or rb_check_id_cstr().
* object.c: ditto.
* struct.c: ditto.
* thread.c: ditto.
* vm_method.c: ditto.
* string.c (sym_find): use only rb_check_symbol().
* sprintf.c (rb_str_format): use rb_check_symbol_cstr().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-09 06:14:41 +00:00
nobu 69e9b27a28 string.c: do not use garbage object
* string.c (fstr_update_callback): should not access garbage
  object contents, copy from the argument instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-06 23:47:17 +00:00
ko1 7ad35210a3 * string.c (fstr_update_callback): do not use rb_gc_resurrect()
any more.
  Make new frozen string and replace with garbage frozen string.
* common.mk: use gc.h from string.c.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-06 17:20:30 +00:00
nobu 72194a89da string.c: rb_fstring_new assumes US-ASCII
* string.c (rb_fstring_new): make US-ASCII string.  another
  function may be used for non-ASCII strings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-04 06:32:44 +00:00
nobu 58bd5facb2 string.c: rb_fstring_new
* string.c (rb_fstring_new): create fstring from pointer and
  length.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-30 14:59:44 +00:00
nobu ca65a56bd8 string.c: no copy of interned strings
* string.c (sym_succ, sym_cmp, sym_casecmp, sym_match, sym_aref):
  not need to make copy of interned strings, use directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-16 08:06:39 +00:00
nobu 9729275473 string.c: fix wrong capa
* string.c (rb_str_resize): update capa only when buffer get
  reallocated.
  http://d.hatena.ne.jp/nagachika/20140613/ruby_trunk_changes_46413_46420#r46413

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-14 01:53:32 +00:00
nobu 85bbacbba2 string.c: consider capacity
* string.c (rb_str_resize): should consider the capacity instead
  of the old length, as pointed out by nagachika.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-12 11:33:12 +00:00
nobu d07a013cf9 string.c: shrink before freezing
* string.c (rb_str_freeze): shrink the buffer before freezing, as
  pointed out by Eric Wong at [ruby-core:63119].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-12 04:28:16 +00:00
nobu b35a6f91d2 string.c: shrink too big buffer
* string.c (rb_str_resize): shrink the buffer even if new length
  is same but it is enough smaller than the capacity.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-12 04:09:26 +00:00
nobu d9e00a7d00 string.c: update rdoc of rb_str_slice_bang()
* string.c (rb_str_slice_bang): [DOC] update return value against
  a fixnum, which has changed because of M17N.  [fix GH-631]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-07 19:52:43 +00:00
nobu f2980e3e20 encoding.h: constify rb_encoding
* include/ruby/encoding.h: constify `rb_encoding` itself, not only
  arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-02 20:23:47 +00:00
nobu 046831094b constify rb_encoding and OnigEncoding
* include/ruby/encoding.h: constify `rb_encoding` arguments.
* include/ruby/oniguruma.h: constify `OnigEncoding` arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-01 22:06:11 +00:00
nobu 950508e9b7 string.c: reset code range
* string.c (rb_str_substr): need to reset code range for shared
  string too, not only copied string.
  [ruby-core:62842] [Bug #9882]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-30 02:33:38 +00:00
nobu 8fb925dfcd string.c: byte offset
* string.c (rb_pat_search): advance by byte offset but not by char
  offset.  [ruby-core:62669] [Bug #9849]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-19 07:29:51 +00:00
nobu 72c773b15d string.c: constify
* string.c (rb_str_index): constify local pointer variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-19 07:06:54 +00:00
naruse df645bf79c * string.c (rb_str_coderange_scan_restartable): coderange is always
ENC_CODERANGE_VALID if the string is ASCII-8BIT and already has a non
  ASCII character.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-21 10:15:54 +00:00
naruse 9f2ddef227 * string.c (coderange_scan): remove useless condtion `p < e` after
search_nonascii.

* string.c (rb_str_coderange_scan_restartable): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-21 10:15:20 +00:00
naruse 8377e9e435 * string.c (coderange_scan): remove unused logic.
* string.c (rb_str_coderange_scan_restartable): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-21 10:14:43 +00:00
nobu 8581ce328d string.c: rename rb_str_splice as rb_str_update
* string.c (rb_str_update): rename rb_str_splice as exported name
  rb_str_update, and make the former an alias macro of the latter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-21 08:31:30 +00:00
nobu 07cad43677 string.c: SHARABLE_SUBSTRING_P
* string.c (SHARABLE_SUBSTRING_P): predicate if substring can be
  shared with the original string.  true if just at the end of the
  original string, for the time being.  all substring will be able to
  be shared in the future.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 15:17:21 +00:00
nobu 609a6ebac5 string.c: share middle of a string
* string.c (rb_str_new_frozen): consider the shared string at
  middle.
* string.c (rb_str_subseq, rb_str_substr, str_byte_substr): share
  middle of a string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 12:48:26 +00:00
nobu 39fe6aa304 string.c: revert r45622
* string.c (str_buf_cat): revert r45622.  broken data can be added
  later.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 08:27:09 +00:00
nobu 46c3749996 string.c: r45621
* string.c (str_buf_cat): revert r45621.  this function does not
  scan appended data.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 08:17:44 +00:00
nobu af2228a08d string.c: don't clear coderange at expanding
* string.c (rb_str_modify_expand): like as str_modify_keep_cr,
  don't clear coderange unless broken.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 08:00:04 +00:00
nobu 0ee6aff847 string.c: keep code range
* string.c (str_buf_cat): keep code range if possible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 07:55:04 +00:00
naruse fb1b9a78b7 * string.c: use uintptr_t instead of VALUE because they are not ruby
object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 06:43:29 +00:00
naruse cbab67a1ac * string.c: check str_strlen's argument, and add comment or
use NULL if simply it uses str's enc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 06:43:11 +00:00
naruse c37ac7ba91 * string.c (str_strlen): use enc_strlen if the coderange is known.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 06:43:08 +00:00
naruse 0ab9abe069 * string.c (enc_strlen): move UTF-8 optimization from str_strlen to
enc_strlen.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 06:42:51 +00:00
nobu a0209e4845 string.c: argument check
* string.c (rb_str_cat_cstr): check the argument as other `_cstr`
  functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-17 05:23:00 +00:00
nobu 37dffb599d string.c: rb_str_cat_cstr
* string.c (rb_str_cat): make non-buf version main.

* string.c (rb_str_cat_cstr): rename from rb_str_cat2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-17 05:22:57 +00:00
nobu 3784395b8d string.c: alias of rb_str_buf_cat and rb_str_buf_cat2
* string.c (rb_str_cat, rb_str_cat2): make aliases of
  rb_str_buf_cat and rb_str_buf_cat2 respectively.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-17 02:41:36 +00:00
nobu df66229230 string.c: reduce duplicated code
* string.c (rb_str_cat, rb_str_cat2): reduce duplicated code, they
  are same as rb_str_buf_cat and rb_str_buf_cat2 respectively now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-17 02:41:34 +00:00
nobu 982618ed7e string.c: reduce function calls
* string.c (rb_enc_cr_str_buf_cat): reduce invariant function
  calls of rb_enc_from_index.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-14 05:33:42 +00:00
nobu 925cc8ffd0 string.c: keep source code range
* string.c (rb_enc_cr_str_buf_cat): keep code range of the source
  string even if code range of the destination string is unknown.
  no reason to the former is affected by the latter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-14 05:33:40 +00:00
nobu 2f3b28c682 string.c: clear env self in symbol proc
* string.c (sym_to_proc), proc.c (rb_block_clear_env_self): clear
  caller's self which is useless, so that it can get collected.
  [Fixes GH-592]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-12 13:11:11 +00:00
nobu 5c7564c9e2 string.c: remove unnecessary terminator space
* string.c (str_buf_cat): remove unnecessary terminator space,
  since the capacity does not include its length but RESIZE_CAPA()
  considers it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-09 03:50:07 +00:00
nobu 68537a4219 string.c: fix capacity
* string.c (str_buf_cat): should round up the capacity by 4KiB,
  but not number of rooms.  [ruby-core:61886] [Bug #9709]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-09 03:44:55 +00:00
ktsj e4879afe3e * parse.y (rb_str_dynamic_intern): [DOC] move rdoc from rb_str_intern.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-30 08:10:04 +00:00
nobu 9d1bf5b33a string.c: infect match result
* string.c (rb_pat_search): match result should be infected by the
  pattern.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-28 02:28:18 +00:00
nobu 2f14bde88f string.c: backref substitution
* re.c (rb_reg_regsub): allow nil regexp for string matching.

* string.c (rb_str_sub_bang, str_gsub): make substitution if
  replacement string has backref escapes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-28 02:28:16 +00:00
nobu 2d82342cf2 string.c: unset $~ if unmatch
* string.c (rb_pat_search): unset $~ if the last match failed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-28 02:27:14 +00:00
nobu fb3bd78725 string.c: suppress warnings
* string.c (rb_str_sub_bang, str_gsub): initialize conditionally
  assigned variables to suppress maybe-uninitialized warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-27 12:03:36 +00:00
nobu 5752b61d86 string.c: search by rb_str_index
* re.c (match_regexp): set regexp for MatchData from string.
* re.c (rb_backref_set_string): create MatchData from string and
  set backref.
* string.c (rb_pat_search, rb_str_sub, rb_str_sub_bang, str_gsub),
  (scan_once, rb_str_scan, rb_str_partition): use rb_str_index
  instead of rb_reg_search() when pattern is a String.  based on
  the patch by Sam Rawlins <sam.rawlins@gmail.com> [Fixes GH-579]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-27 09:58:12 +00:00
nobu 227a5a2aae string.c: mustnot_broken
* string.c (mustnot_broken): extract function to reject invalid
  byte sequence, from rb_str_split_m().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-27 09:47:03 +00:00
nobu 949f1160d6 string.c: invert flag
* string.c (str_gsub): invert and rename `str_replace` flag as
  `need_backref`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-27 03:03:19 +00:00
nari 90b7073842 * parse.y: support Symbol GC. [ruby-trunk Feature #9634]
See this ticket about Symbol GC.

* include/ruby/ruby.h:
  Declare few functions.
  * rb_sym2id: almost same as old SYM2ID but support dynamic symbols.
  * rb_id2sym: almost same as old ID2SYM but support dynamic symbols.
  * rb_sym2str: almost same as `rb_id2str(SYM2ID(sym))` but not
    pin down a dynamic symbol.
  Declare a new struct.
  * struct RSymbol: represents a dynamic symbol as object in
    Ruby's heaps.
  Add few macros.
  * STATIC_SYM_P: check a static symbol.
  * DYNAMIC_SYM_P: check a dynamic symbol.
  * RSYMBOL: cast to RSymbol

* gc.c: declare RSymbol. support T_SYMBOL.

* internal.h: Declare few functions.
  * rb_gc_free_dsymbol: free up a dynamic symbol. GC call this
    function at a sweep phase.
  * rb_str_dynamic_intern: convert a string to a dynamic symbol.
  * rb_check_id_without_pindown: not pinning function.
  * rb_sym2id_without_pindown: ditto.
  * rb_check_id_cstr_without_pindown: ditto.

* string.c (Init_String): String#intern and String#to_sym use
  rb_str_dynamic_intern.

* template/id.h.tmpl: use LSB of ID as a flag for determining a
  static symbol, so we shift left other ruby_id_types.

* string.c: use rb_sym2str instead `rb_id2str(SYM2ID(sym))` to
  avoid pinning.

* load.c: use xx_without_pindown function at creating temporary ID
  to avoid pinning.

* object.c: ditto.

* sprintf.c: ditto.

* struct.c: ditto.

* thread.c: ditto.

* variable.c: ditto.

* vm_method.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-26 04:57:47 +00:00
charliesome a77206582e Stop allocating backref strings within gsub's search loop
* internal.h: add prototype for rb_reg_search0

* re.c: rename rb_reg_search to rb_reg_search0, add set_backref_str
  argument to allow callers to indicate that they don't require the
  backref string to be allocated

* string.c: don't allocate backref str if replacement string is provided

Closes GH-578. [Bug #9676] [ruby-core:61682]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-25 23:46:05 +00:00
nobu fc23374f06 [DOC] add links to `Object#hash`
add links to `Object#hash` to each #`hash` methods rdocs.
[Fixes GH-567]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:43 +00:00
nobu f53c291ab2 string.c: [DOC] rb_str_hash_m
* string.c (rb_str_hash_m): [DOC] hash value depends on the
  encoding too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:41 +00:00
nobu cc216f9aae adjust indent and style
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-27 07:10:14 +00:00
naruse 0b5685a69b * string.c (sym_find): Add Symbol.find(str), which returns whether given
string is defined as symbol or not. [Feature #7854]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-25 16:34:00 +00:00
normal f7cff3a940 string.c (rb_str_format_m): trade volatile for RB_GC_GUARD
* string.c (rb_str_format_m): trade volatile for RB_GC_GUARD
  RB_GC_GUARD meaning is clear and has better code generation.
  [ruby-core:60688]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-14 09:42:14 +00:00
ko1 1ccaa4756a * internal.h, vm_core.h: move LIKELY/UNLIKELY/UNINITIALIZED_VAR()
macros from vm_core.h to internal.h.
* string.c: remove dependency to "vm_core.h".
* common.mk: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-05 04:58:00 +00:00
ko1 3889ce2d15 * string.c (rb_str_free): use FL_TEST(str, STR_SHARED) directly
because str is not embed.
* string.c (str_replace): remove `FL_SET(str, STR_SHARED)' line
  because STR_SET_SHARED() set STR_SHARED.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-05 04:31:18 +00:00
ko1 38cd45a3cd * internal.h: remove macros STR_NOCAPA and STR_NOCAPA_P().
* string.c (rb_str_resize): remove `STR_SET_NOEMBED(str)' because
  str_make_independent_expand() set NOEMBED flag.
* string.c (rb_str_resize): remove `STR_NOCAPA_P(str)' check because
  `str' is independent (not shared).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-05 04:21:30 +00:00
ko1 84d8104ed6 * string.c: refactoring, especially about string flags.
* string.c (STR_UNSET_NOCAPA): removed.
  Use FL_UNSET() with STR_SHARED.
* string.c (rb_str_capacity): check STR_SHARED directly
  beacuse it is not a embed string.
* string.c (rb_str_modify_expand): ditto.
* string.c (rb_str_shared_replace): use STR_SET_SHARED().
* string.c (str_make_independent_expand): remove STR_UNSET_NOCAPA()
  because `str' is not shared string.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-05 04:00:02 +00:00
ko1 46fcec9a17 * string.c (RESIZE_CAPA): should not resize shared string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-05 03:14:23 +00:00
ko1 62bd0f180f * string.c (rb_str_new_frozen): refactoring code.
* Move code from str_new_frozen_with_klass() (and remove it)
  * `aux.shared' should not be 0 for STR_SHARED strings.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-05 02:45:29 +00:00
ko1 fc4321ea3f * string.c: use long allocator names instead of numbered
allocator names.
  * rb_str_new2 -> rb_str_new_cstr
  * rb_str_new4 -> rb_str_new_frozen
  * rb_str_new5 -> rb_str_new_with_class
  * str_new3 -> str_new_shared
  * str_new4 -> str_new_frozen_with_klass



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-04 10:17:52 +00:00
ko1 171a14b36c * string.c: use STR_SHARED instead of ELTS_SHARED.
(same value, but more clear meaning)



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-04 07:17:59 +00:00
ko1 c77a745aab * string.c: remvoe STR_ASSOC related code.
By r44804, string objects can not have STR_ASSOC flag.
* internal.h: ditto.
* ext/objspace/objspace_dump.c (dump_object): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-04 07:12:49 +00:00
nobu 4b146b2533 pack.c: use ivar for associated objects
* pack.c (str_associate, str_associated): keep associated objects
  in an instance variables, instead of in the internal structure.
* string.c (rb_str_associate, rb_str_associated): deprecate.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-04 05:07:21 +00:00
nobu bebc52a4a7 string.c: enable capacity when setting capa
* string.c (rb_str_modify_expand): enable capacity and disable
  assocation with packed objects when setting capa, so that
  pack("p") string fails to unpack properly after modified.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-04 03:55:32 +00:00
nobu 6951fbca43 string.c: respect BOM
* string.c (get_encoding): respect BOM on pseudo encodings.
  [ruby-dev:47895] [Bug #9415]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-15 05:04:36 +00:00
nobu 77ae7b2e83 string.c: use actual encodings
* string.c (get_actual_encoding): get actual encoding according to
  the BOM if exists.
* string.c (rb_str_inspect): use according encoding, instead of
  pseudo encodings, UTF-{16,32}.  [ruby-core:59757] [Bug #8940]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44605 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-15 05:03:49 +00:00
ko1 c702005a7b * include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
  proc.c, process.c, re.c, string.c, variable.c, vm.c,
  vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
  vm_method.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 08:07:47 +00:00
tmm1 98a74d4dd5 parse.y: use rb_fstring() for strings stored in the symbol table
* parse.y (register_symid_str): use fstrings in symbol table
  [Bug #9171] [ruby-core:58656]
* parse.y (rb_id2str): ditto
* string.c (rb_fstring): create frozen_strings on first usage. this
  allows rb_fstring() calls from the parser (before cString is created)
* string.c (fstring_set_class_i): set klass on fstrings generated
  before cString was defined
* string.c (Init_String): convert frozen_strings table to String
  objects after boot
* ext/-test-/symbol/type.c (bug_sym_id2str): expose rb_id2str()
* test/-ext-/symbol/test_type.rb (module Test_Symbol): verify symbol
  table entries are fstrings

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 01:39:27 +00:00
nobu efbcd1cb25 * string.c (rb_str_scrub): [DOC] add param str.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 13:05:04 +00:00
nobu 5a7ee1e117 string.c: fix declaration-after-statement
* string.c (fstr_update_callback): move a variable declaration since
  ISO C90 forbids mixed declarations and code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-04 04:20:15 +00:00
tmm1 753fe47175 * string.c (fstr_update_callback): Improve implementation in r43968
based on feedback from @nagachika. In the existing case, we can
  return ST_STOP to prevent any hash modification. In the !existing
  case, set both key and value to the fstr.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-04 04:05:13 +00:00
tmm1 6edaf997e3 * string.c (rb_fstring): Use st_update instead of st_lookup +
st_insert.
* string.c (fstr_update_callback): New callback for st_update.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 03:40:56 +00:00