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

238 Коммитов

Автор SHA1 Сообщение Дата
shyouhei 289972277a st.c: fix comparison between signed and unsigned
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 05:24:07 +00:00
shyouhei 24fff75045 avoid (size_t)--
The decrements overflow and these variables remain ~0 when leaving the
while loops.  They are not fatal by accident, but better replace with
ordinal for loops.

See also: https://travis-ci.org/ruby/ruby/jobs/452218871#L3246


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 05:06:52 +00:00
shyouhei 96af6823c1 st.c: straight-forward comparison of characters
These functions are used in strcasehash, which is used to store encoding
names.  Encoding names often include hyphens (e.g. "UTF-8"), and
` '-' - 'A' ` is negative (cannot express in unsigned int).

Don't be tricky, just do what to do.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 04:24:26 +00:00
shyouhei 96c26fbba3 st.c: suppress integer overlow warnings
This `i += h;` overflows.  Don't know the intention of the
operation, so just suppress UBSAN.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 01:43:07 +00:00
shyouhei 234ffbce0e blacklist UBSAN's unsigned integer overflow
Integer overflow for unsigned types are fully defined in C. They
are not always problematic (but not always OK).  These functions
in this changeset intentionally utilizes that behaviour.
Blacklist from UBSAN checks for better output.

See also: https://travis-ci.org/ruby/ruby/jobs/451624829


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-07 04:09:05 +00:00
ko1 8f675cdd00 support theap for T_HASH. [Feature #14989]
* hash.c, internal.h: support theap for small Hash.
  Introduce RHASH_ARRAY (li_table) besides st_table and small Hash
  (<=8 entries) are managed by an array data structure.
  This array data can be managed by theap.
  If st_table is needed, then converting array data to st_table data.

  For st_table using code, we prepare "stlike" APIs which accepts hash value
  and are very similar to st_ APIs.

  This work is based on the GSoC achievement
  by tacinight <tacingiht@gmail.com> and refined by ko1.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:11:51 +00:00
k0kubun 783e2b579c st.c: remove redundant export declaration
rb_hash_bulk_insert is added to official C API in r63488. It's no longer
exported only for MJIT.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-27 05:52:43 +00:00
normal 4663c224fa st.c: retry operations if rebuilt
Calling the .eql? and .hash methods during a Hash operation can
result in a thread switch or a signal handler to run: allowing
one execution context to rebuild the hash table while another is
still reading or writing the table.  This results in a
use-after-free bug affecting the thread_safe-0.3.6 test suite
and likely other bugs.

This bug did not affect users of commonly keys (String, Symbol,
Fixnum) as those are optimized to avoid method dispatch
for .eql? and .hash methods.

A separate version of this change needs to be ported to Ruby 2.3.x
which had a different implementation of st.c but was affected
by the same bug.

* st.c: Add comment about table rebuilding during comparison.
  (DO_PTR_EQUAL_CHECK): New macro.
  (REBUILT_TABLE_ENTRY_IND, REBUILT_TABLE_BIN_IND): New macros.
  (find_entry, find_table_entry_ind, find_table_bin_ind): Use new
  macros.  Return the rebuild flag.
  (find_table_bin_ptr_and_reserve): Ditto.
  (st_lookup, st_get_key, st_insert, st_insert2): Retry the
  operation if the table was rebuilt.
  (st_general_delete, st_shift, st_update, st_general_foreach):
  Ditto.
  (st_rehash_linear, st_rehash_indexed): Use DO_PTR_EQUAL_CHECK.
  Return the rebuild flag.
  (st_rehash): Retry the operation if the table was rebuilt.
  [ruby-core:85510] [Ruby trunk Bug#14357]

Thanks to Vit Ondruch for reporting the bug.

From: Vladimir Makarov <vmakarov@redhat.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 10:02:07 +00:00
k0kubun ed935aa5be mjit_compile.c: merge initial JIT compiler
which has been developed by Takashi Kokubun <takashikkbn@gmail> as
YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>.

This JIT compiler is designed to be a safe migration path to introduce
JIT compiler to MRI. So this commit does not include any bytecode
changes or dynamic instruction modifications, which are done in original
MJIT.

This commit even strips off some aggressive optimizations from
YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still
fairly faster than Ruby 2.5 in some benchmarks (attached below).

Note that this JIT compiler passes `make test`, `make test-all`, `make
test-spec` without JIT, and even with JIT. Not only it's perfectly safe
with JIT disabled because it does not replace VM instructions unlike
MJIT, but also with JIT enabled it stably runs Ruby applications
including Rails applications.

I'm expecting this version as just "initial" JIT compiler. I have many
optimization ideas which are skipped for initial merging, and you may
easily replace this JIT compiler with a faster one by just replacing
mjit_compile.c. `mjit_compile` interface is designed for the purpose.

common.mk: update dependencies for mjit_compile.c.

internal.h: declare `rb_vm_insn_addr2insn` for MJIT.

vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to
compiler. This avoids to include some functions which take a long time
to compile, e.g. vm_exec_core. Some of the purpose is achieved in
transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are
manually resolved for now. Load mjit_helper.h for MJIT header.
mjit_helper.h: New. This is a file used only by JIT-ed code. I'll
refactor `mjit_call_cfunc` later.
vm_eval.c: add some #ifdef switches to skip compiling some functions
like Init_vm_eval.

win32/mkexports.rb: export thread/ec functions, which are used by MJIT.

include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify
that a function is exported only for MJIT.

array.c: export a function used by MJIT.
bignum.c: ditto.
class.c: ditto.
compile.c: ditto.
error.c: ditto.
gc.c: ditto.
hash.c: ditto.
iseq.c: ditto.
numeric.c: ditto.
object.c: ditto.
proc.c: ditto.
re.c: ditto.
st.c: ditto.
string.c: ditto.
thread.c: ditto.
variable.c: ditto.
vm_backtrace.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.

I would like to improve maintainability of function exports, but I
believe this way is acceptable as initial merging if we clarify the
new exports are for MJIT (so that we can use them as TODO list to fix)
and add unit tests to detect unresolved symbols.
I'll add unit tests of JIT compilations in succeeding commits.

Author: Takashi Kokubun <takashikkbn@gmail.com>
Contributor: wanabe <s.wanabe@gmail.com>

Part of [Feature #14235]

---

* Known issues
  * Code generated by gcc is faster than clang. The benchmark may be worse
    in macOS. Following benchmark result is provided by gcc w/ Linux.
  * Performance is decreased when Google Chrome is running
  * JIT can work on MinGW, but it doesn't improve performance at least
    in short running benchmark.
  * Currently it doesn't perform well with Rails. We'll try to fix this
    before release.

---

* Benchmark reslts

Benchmarked with:
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores

- 2.0.0-p0: Ruby 2.0.0-p0
- r62186: Ruby trunk (early 2.6.0), before MJIT changes
- JIT off: On this commit, but without `--jit` option
- JIT on: On this commit, and with `--jit` option

** Optcarrot fps

Benchmark: https://github.com/mame/optcarrot

|         |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:--------|:--------|:--------|:--------|:--------|
|fps      |37.32    |51.46    |51.31    |58.88    |
|vs 2.0.0 |1.00x    |1.38x    |1.37x    |1.58x    |

** MJIT benchmarks

Benchmark: https://github.com/benchmark-driver/mjit-benchmarks
(Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks)

|           |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:----------|:--------|:--------|:--------|:--------|
|aread      |1.00     |1.09     |1.07     |2.19     |
|aref       |1.00     |1.13     |1.11     |2.22     |
|aset       |1.00     |1.50     |1.45     |2.64     |
|awrite     |1.00     |1.17     |1.13     |2.20     |
|call       |1.00     |1.29     |1.26     |2.02     |
|const2     |1.00     |1.10     |1.10     |2.19     |
|const      |1.00     |1.11     |1.10     |2.19     |
|fannk      |1.00     |1.04     |1.02     |1.00     |
|fib        |1.00     |1.32     |1.31     |1.84     |
|ivread     |1.00     |1.13     |1.12     |2.43     |
|ivwrite    |1.00     |1.23     |1.21     |2.40     |
|mandelbrot |1.00     |1.13     |1.16     |1.28     |
|meteor     |1.00     |2.97     |2.92     |3.17     |
|nbody      |1.00     |1.17     |1.15     |1.49     |
|nest-ntimes|1.00     |1.22     |1.20     |1.39     |
|nest-while |1.00     |1.10     |1.10     |1.37     |
|norm       |1.00     |1.18     |1.16     |1.24     |
|nsvb       |1.00     |1.16     |1.16     |1.17     |
|red-black  |1.00     |1.02     |0.99     |1.12     |
|sieve      |1.00     |1.30     |1.28     |1.62     |
|trees      |1.00     |1.14     |1.13     |1.19     |
|while      |1.00     |1.12     |1.11     |2.41     |

** Discourse's script/bench.rb

Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb

NOTE: Rails performance was somehow a little degraded with JIT for now.
We should fix this.
(At least I know opt_aref is performing badly in JIT and I have an idea
 to fix it. Please wait for the fix.)

*** JIT off
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 17
  75: 18
  90: 22
  99: 29
home_admin:
  50: 21
  75: 21
  90: 27
  99: 40
topic_admin:
  50: 17
  75: 18
  90: 22
  99: 32
categories:
  50: 35
  75: 41
  90: 43
  99: 77
home:
  50: 39
  75: 46
  90: 49
  99: 95
topic:
  50: 46
  75: 52
  90: 56
  99: 101

*** JIT on
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 19
  75: 21
  90: 25
  99: 33
home_admin:
  50: 24
  75: 26
  90: 30
  99: 35
topic_admin:
  50: 19
  75: 20
  90: 25
  99: 30
categories:
  50: 40
  75: 44
  90: 48
  99: 76
home:
  50: 42
  75: 48
  90: 51
  99: 89
topic:
  50: 49
  75: 55
  90: 58
  99: 99

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 11:22:28 +00:00
shyouhei 5fef2139d4 st_hashtype_num marked as static
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19 03:55:16 +00:00
shyouhei 39cfa67b4f __builtin_assume_aligned for *(foo *) casts
These casts are guarded. Must be safe to assume alignments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-15 02:35:18 +00:00
normal fc939f6697 hash literal deduplicates like Hash#[]=
From: Eric Wong <e@80x24.org>

* hash.c (rb_hash_key_str): new function
  (hash_aset_str): use rb_hash_key_str
* internal.h: add rb_hash_key_str
* st.c (st_stringify): use rb_hash_key_str
* test/ruby/test_hash.rb (test_NEWHASH_fstring_key): dynamic key
  [ruby-core:84554] [Feature #14258]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-30 00:00:23 +00:00
watson1978 2e6235aa71 Revert "Improve performance of creating Hash object"
This reverts commit r61309
Because it was unstable on mswin CI.

[ruby-dev:50370][Bug #14203]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-19 14:26:30 +00:00
nobu d20f4eb169 st.c: fix up
* st.c (_st_table_list, _st_table_pool): symbols beginning with an
  underscore and a lower letter are preserved by the standard.

* st.c (get_st_table): protoized.

* st.c (st_insert_generic): adjust local variable type to an
  argument argc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-19 12:20:21 +00:00
nobu 7766fcc732 st.c: no C99 comment
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-18 01:54:19 +00:00
watson1978 07d48bbe13 Improve performance of creating Hash object
When generate Hash object, the heap area of st_table will be always allocated in internally
and seems it take a time.

To improve performance of creating Hash object,
this patch will reduce count of allocating heap areas for st_table by reuse them.

	Performance of creating Hash literal -> 1.53 times faster.

[Fix GH-1766] [ruby-core:84008] [Feature #14146]

### Environment

* OS : macOS 10.13.1
* CPU : 1.4 GHz Intel Core i7
* Compiler : Apple LLVM version 9.0.0 (clang-900.0.39)

### Before

$ ./miniruby -v -I. -I../benchmark-ips/lib ~/tmp/bench/literal.rb
ruby 2.5.0dev (2017-11-28 hash 60926) [x86_64-darwin17]
Warming up --------------------------------------
        Hash literal    51.544k i/100ms
Calculating -------------------------------------
        Hash literal    869.132k (± 1.1%) i/s -      4.381M in   5.041574s

### After

$ ./miniruby -v -I. -I../benchmark-ips/lib ~/tmp/bench/literal.rb
ruby 2.5.0dev (2017-11-28 hash 60926) [x86_64-darwin17]
Warming up --------------------------------------
        Hash literal    63.068k i/100ms
Calculating -------------------------------------
        Hash literal      1.328M (± 2.3%) i/s -      6.685M in   5.037861s

### Test code

require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "Hash literal" do |loop|
    count = 0
    while count < loop
      hash = {foo: 12, bar: 34, baz: 56}

      count += 1
    end
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-18 01:49:33 +00:00
nobu 813ffb8b53 st.c: fix num_entries
* st.c (st_insert2): should manage num_entries when the key is
  undefined, as well as st_insert().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-05 07:52:08 +00:00
nobu 4a09333b35 st.c: fix false assertions
* st.c: split assertion conditions.

* st.c (rb_hash_bulk_insert): the number of arguments should be
  even.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-05 07:50:13 +00:00
shyouhei ce7f3e13c1 optimize rb_hash_bulk_insert to generally outperform 2.4.
Specialized routine for small linear-probling hash instances to
boost creation of such things [Bug #13861]

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-05 04:49:01 +00:00
nobu 2cc3946d0e st.c: adjust style
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-19 02:28:45 +00:00
normal 0493b1ce3a revert r59359, r59356, r59355, r59354
These caused numerous CI failures I haven't been able to
reproduce [ruby-core:82102]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-19 01:35:04 +00:00
normal 4f473905e1 newhash insn reuses existing keys
This gives the newhash VM instruction the same string reuse
capabilities as rb_hash_aset.

* st.c (str_key): new wrapper function to call rb_fstring_existing
  (rb_hash_bulk_insert): use str_key
* test/ruby/test_optimization.rb (test_hash_reuse_fstring):
  ensure key reuse for newhash instructions

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-18 04:30:08 +00:00
nobu 6924066a65 adjust styles [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-10 00:39:26 +00:00
shyouhei 29ca20de2d refactor newhash (revision 58463 another try) [fix GH-1600]
* st.c (rb_hash_bulk_insert): new API to bulk insert entries
	  into a hash. Given arguments are first inserted into the
	  table at once, then reindexed. This is faster than inserting
	  things using rb_hash_aset() one by one.

	  This arrangement (rb_ prefixed function placed in st.c) is
	  unavoidable because it both touches table internal and write
	  barrier at once.

	* internal.h: delcare the new function.

	* hash.c (rb_hash_s_create): use the new function.

	* vm.c (core_hash_merge): ditto.

	* insns.def (newhash): ditto.

	* test/ruby/test_hash.rb: more coverage on hash creation.

	* test/ruby/test_literal.rb: ditto.

-----------------------------------------------------------
benchmark results:
minimum results in each 7 measurements.
Execution time (sec)
name    before  after
loop_whileloop2  0.136  0.137
vm2_bighash*     1.249  0.623

Speedup ratio: compare with the result of `before' (greater is better)
name    after
loop_whileloop2 0.996
vm2_bighash*    2.004



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-27 04:21:04 +00:00
shyouhei 766864166f fix macro expansion bug
This previous "key" macro argument accidentally replaced `(ptr)->key` part. 


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25 06:51:34 +00:00
nobu 23ba6b2eb9 st.c: suppress a warning
* st.c (st_hash): suppress unused label warning on 32bit
  platforms.  fix up r57134.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 11:20:02 +00:00
nobu c0ff5f4dd7 st.c: fix st_hash* functions [Bug #13019]
Previous implementation had an issues:
- macros murmur1 assumes murmur_step takes rotation value
  as a second argument
- but murmur_step second argument is "next block"
- this makes st_hash_uint and st_hash_end to not mix high bits of
  hash value into lower bits
- this leads to pure hash behavior on doubles and mixing hashes using
  st_hash_uint.
  It didn't matter when bins amount were prime numbers, but it hurts
  when bins are powers of two.

Mistake were created cause of attempt to co-exist Murmur1 and Murmur2
in a same code.

Change it to single hash-function implementation.
- block function is in a spirit of Murmur functions,
  but handles inter-block dependency a bit better (imho).
- final block is read in bit more optimal way on CPU with unaligned word access,
- final block is mixed in simple way,
- finalizer is taken from MurmurHash3 (it makes most of magic :) )
  (64bit finalizer is taken from
  http://zimbry.blogspot.ru/2011/09/better-bit-mixing-improving-on.html)

Also remove ST_USE_FNV1: it lacks implementation of many functions,
and looks to be abandoned

Author: Sokolov Yura aka funny_falcon <funny.falcon@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 06:22:16 +00:00
naruse 31f17f880e st: Add 'static const'
patched by Ken Takata [ruby-core:78558]
44e3c0a16d

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-12 14:55:15 +00:00
nobu 5714a26b90 switching hash removal
* st.h (struct st_hash_type): Remove strong_hash.
  (struct st_table): Remove inside_rebuild_p and curr_hash.
* st.c (do_hash): Use type->hash instead of curr_hash.
  (make_tab_empty): Remove setting up curr_hash.
  (st_init_table_with_size): Remove setting up inside_rebuild_p.
  (rebuild_table): Remove clearing inside_rebuild_p.
  (reset_entry_hashes, HIT_THRESHOULD_FOR_STRONG_HASH): Remove code
  recognizing a denial attack and switching to strong hash.
* hash.c (rb_dbl_long_hash, rb_objid_hash, rb_ident_hash): Use
  rb_hash_start to randomize the hash.
  (str_seed): Remove.
  (any_hash): Remove strong_p and use always rb_str_hash for
  strings.
  (any_hash_weak, rb_any_hash_weak): Remove.
  (st_hash_type objhash): Remove rb_any_hash_weak.

based on the patch by Vladimir N Makarov <vmakarov@redhat.com> at
[ruby-core:78490].  [Bug #13002]

* test/ruby/test_hash.rb (test_wrapper): objects other than special
  constants should be able to be wrapped.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 04:43:48 +00:00
nobu 1e95f9da88 remove unnecessary variable
* st.c (do_hash): remove unnecessary variable and cast.

* hash.c, numeric.c, st.c: adjust style and indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 03:36:52 +00:00
normal f46a43fc58 st.c: fix crashes on huge hash tables
From: Vladimir Makarov <vmakarov@redhat.com>

By Vladimir's estimation, this requires at least 64 GB of memory
to reproduce this bug due to the hash sizes required.  So there
is no new test case (and I am unable to test it, myself).

* st.c (get_bins_num): avoid out-of-bounds on shift by using correct type
  [ruby-core:78139] [Bug #12939]
* st.c (get_allocated_entries): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-15 00:27:20 +00:00
ko1 75775157ea Introduce table improvement by Vladimir Makarov <vmakarov@redhat.com>.
[Feature #12142]
	See header of st.c for improvment details.

	You can see all of code history here:
	<https://github.com/vnmakarov/ruby/tree/hash_tables_with_open_addressing>

	This improvement is discussed at
	<https://bugs.ruby-lang.org/issues/12142>
	with many people, especially with Yura Sokolov.

	* st.c: improve st_table.

	* include/ruby/st.h: ditto.

	* internal.h, numeric.c, hash.c (rb_dbl_long_hash): extract a function.

	* ext/-test-/st/foreach/foreach.c: catch up this change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-07 00:45:00 +00:00
naruse 28f5e12c24 * configure.in: check function attirbute const and pure,
and define CONSTFUNC and PUREFUNC if available.
  Note that I don't add those options as default because
  it still shows many false-positive (it seems not to consider
  longjmp).

* vm_eval.c (stack_check): get rb_thread_t* as an argument
  to avoid duplicate call of GET_THREAD().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-08 17:44:51 +00:00
naruse b888ee25ff revert UNALIGNED_WORD_ACCESS for GCC6
Released GCC 6.0 fixed the issue.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291
[ruby-core:72211] [Bug #11831] [Bug #11979]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 15:39:03 +00:00
nobu 828270af13 st.c: fix collision statistics [ci skip]
* st.c (stat_col): get rid of NaN.

* st.c (collision_check): define before used.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-30 13:02:16 +00:00
nobu fd7b490fc3 disable unaligned word access
* include/ruby/defines.h, st.c: disable unaligned word access with
  gcc 6 or later.  [Bug #11831]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-15 13:15:39 +00:00
normal d0240cbb6d st.c: constify st_table* in private functions
Minor size reduction on 32-bit x86:

   text	   data	    bss	    dec	    hex	filename
  13742	     24	      0	  13766	   35c6	st.o
  14166	     24	      0	  14190	   376e	st-orig.o

Public API change to be proposed separately.

* st.c (find_entry): constify st_table*
  (find_packed_index_from): ditto
  (find_packed_index): ditto
  (get_keys): ditto
  (get_values): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-29 23:55:23 +00:00
nobu 7d517ffc80 st.c: fix arguments order to compare
* st.c (EQUAL, st_delete_safe): fix arguments order to compare
  function, searching key is the first and stored key is the
  second always.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-24 12:29:57 +00:00
usa 37c8a704bf * st.c: get rid of VC++'s warnings of C4700 (uninitialized local
variable used).  I think that these are wrong, but should shut them
  up.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-02 05:48:14 +00:00
normal c31b0def42 st.c: use ccan linked-list (try 3)
This improves the bm_vm2_bighash benchmark significantly by
removing branches during insert, but slows down anything
requiring iteration with the more complex loop termination
checking.

Speedup ratio of 1.10 - 1.20 is typical for the vm2_bighash
benchmark.

v3 - st_head calculates list_head address in two steps
     to avoid a bug in old gcc 4.4 (Debian 4.4.7-2)
     bug which incorrectly warned with:
     warning: dereferencing pointer ‘({anonymous})’ does break
     strict-aliasing rules

* include/ruby/st.h (struct st_table): hide struct list_head
* st.c (struct st_table_entry): adjust struct
  (head, tail): remove shortcut macros
  (st_head): new wrapper function
  (st_init_table_with_size): adjust to new struct and API
  (st_clear): ditto
  (add_direct): ditto
  (unpack_entries): ditto
  (rehash): ditto
  (st_copy): ditto
  (remove_entry): ditto
  (st_shift): ditto
  (st_foreach_check): ditto
  (st_foreach): ditto
  (get_keys): ditto
  (get_values): ditto
  (st_values_check): ditto
  (st_reverse_foreach_check): ditto (unused)
  (st_reverse_foreach): ditto (unused)
  [ruby-core:69726] [Misc #10278]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-29 18:10:00 +00:00
normal b8d544832b Revert "st.c: use ccan linked-list (try 2)"
This reverts commit r51044
Still getting failure notices from ko1's CI machine.
ref: g3qkqn

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-26 22:52:26 +00:00
normal d3725a86de st.c: use ccan linked-list (try 2)
This improves the bm_vm2_bighash benchmark significantly by
removing branches during insert, but slows down anything
requiring iteration with the more complex loop termination
checking.

Speedup ratio of 1.10 - 1.20 is typical for the vm2_bighash
benchmark.

* include/ruby/st.h (struct st_table): hide struct list_head
* st.c (struct st_table_entry): adjust struct
  (head, tail): remove shortcut macros
  (st_head): new wrapper function
  (st_init_table_with_size): adjust to new struct and API
  (st_clear): ditto
  (add_direct): ditto
  (unpack_entries): ditto
  (rehash): ditto
  (st_copy): ditto
  (remove_entry): ditto
  (st_shift): ditto
  (st_foreach_check): ditto
  (st_foreach): ditto
  (get_keys): ditto
  (get_values): ditto
  (st_values_check): ditto
  (st_reverse_foreach_check): ditto (unused)
  (st_reverse_foreach): ditto (unused)
  [ruby-core:69726] [Misc #10278]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-26 22:32:06 +00:00
normal c94a94805d st.c: include ccan/list/list.h to test build
I suspect the build failures with r51034 ("st.c: use ccan linked-list")
on ko1's CI machine was due to me forgetting to update common.mk :x

Lets see what happens when I only include ccan/list/list.h
Will followup with appropriate reverts or reinstating the
rest of r51034 along with a common.mk update as I watch CI
build.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-26 18:59:59 +00:00
normal cc5547a4ad Revert r51034 "st.c: use ccan linked-list"
Maybe this will stop mysterious CI failures from ko1@sasada-8core:

リビジョン 51034 です。
make[1]: ディレクトリ `/mnt/sdb1/ruby/build' に入ります
../trunk/revision.h unchanged
make[1]: ディレクトリ `/mnt/sdb1/ruby/build' から出ます
make[1]: ディレクトリ `/mnt/sdb1/ruby/build' に入ります
config.guess already exists
config.sub already exists
generating ../trunk/ext/ripper/ripper.c
make[2]: ディレクトリ `/mnt/sdb1/ruby/trunk/ext/ripper' に入ります
extracting ripper.y from ../../parse.y
id.h not found in ["../.."]
make[2]: *** [ripper.y] エラー 1
make[2]: ディレクトリ `/mnt/sdb1/ruby/trunk/ext/ripper' から出ます
make[1]: *** [../trunk/ext/ripper/ripper.c] エラー 2
make[1]: ディレクトリ `/mnt/sdb1/ruby/build' から出ます
make: [up] エラー 2 (無視されました)
make: *** [.rbconfig.time] セグメンテーション違反です
Command exited with non-zero status 2

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-25 19:56:20 +00:00
normal d8748874cc st.c: use ccan linked-list
This improves the bm_vm2_bighash benchmark significantly by
removing branches during insert, but slows down anything
requiring iteration with the more complex loop termination
checking.

Speedup ratio of 1.10 - 1.20 is typical for the vm2_bighash
benchmark.

* include/ruby/st.h (struct st_table): hide struct list_head
* st.c (struct st_table_entry): adjust struct
  (head, tail): remove shortcut macros
  (st_head): new wrapper function
  (st_init_table_with_size): adjust to new struct and API
  (st_clear): ditto
  (add_direct): ditto
  (unpack_entries): ditto
  (rehash): ditto
  (st_copy): ditto
  (remove_entry): ditto
  (st_shift): ditto
  (st_foreach_check): ditto
  (st_foreach): ditto
  (get_keys): ditto
  (get_values): ditto
  (st_values_check): ditto
  (st_reverse_foreach_check): ditto (unused)
  (st_reverse_foreach): ditto (unused)
  [ruby-core:69726] [Misc #10278]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-25 19:01:25 +00:00
nobu 059ea6e4d8 hash.c: move Hash specific functions
* hash.c (rb_ident_hash): move compare_by_identity specific
  function from st.c.

* hash.c (rb_ident_hash_new): ditto from thread.c.

* st.c (st_numhash): remove ruby's Hash specific implementation.

* thread.c (recursive_list_access): use rb_ident_hash_new().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-23 02:36:50 +00:00
normal 6d56fd067e fix flonum hashing regression from r45384
* st.c (st_numhash): mix float value for flonum
* hash.c (rb_any_hash): ditto
* benchmark/bm_hash_aref_flo.rb: new benchmark
* benchmark/bm_hash_ident_flo.rb: ditto
  [Bug #10761]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-22 07:48:59 +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
nobu 54af8757b3 internal.h: STATIC_ASSERT
* st.c: include "internal.h" for STATIC_ASSERT.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-13 02:56:14 +00:00
nobu 6557a6b9ed st.c: update st_reverse_foreach
* st.c (st_reverse_foreach): update as st_foreach().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-04 14:13:36 +00:00
normal 1b5acebef2 st.c (new_size): use next_pow2 function
Reduces object size slightly on x86-64:

   text	   data	    bss	    dec	    hex	filename
2782359	  22400	  71880	2876639	 2be4df	ruby.orig
2781831	  22400	  71880	2876111	 2be2cf	ruby.pow2

And on 32-bit x86:

   text	   data	    bss	    dec	    hex	filename
2814751	  12100	  30552	2857403	 2b99bb	ruby.orig
2814051	  12100	  30552	2856703	 2b96ff	ruby.pow2

This is not a performance-critical function, but the
smaller icache footprint seems worth it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-02 21:17:13 +00:00
nari a3307d5e5a * st.c (do_hash_bin): unused macro.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-21 10:07:44 +00:00
nari a5c91a3811 * st.c (numberof): unused. internal.h has same macro.
* node.c (F_CUSTOM2): unused.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-21 09:22:42 +00:00
nobu 63360be4d2 UNALIGNED_WORD_ACCESS on ppc64
* include/ruby/defines.h, siphash.c, st.c (UNALIGNED_WORD_ACCESS):
  add PowerPC64 too, which is capable to access unaligned words.
  patched by Gustavo Frederico Temple Pedrosa in [ruby-core:63937].
  [Feature #10081]
* regint.h (PLATFORM_UNALIGNED_WORD_ACCESS): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-23 14:50:12 +00:00
nobu 6a9b242a80 st.c: fix uninitialized variable
* st.c (st_update): old_key is uninitialized by jump to the label
  unpacked.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-06 15:22:19 +00:00
nobu 783b3c8d5a st.c: remove equality checks
* st.c (st_update): remove equality checks, callers should ensure
  the equality, otherwise the behavior is undefined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-06 15:11:53 +00:00
nobu ea74da0c6c st.c: re-calc hash_val before adding
* st.c (st_update): re-calculate hash_val before adding if key was
  changed, otherwise cannot access the newly added element if it
  has different hash value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-06 14:42:57 +00:00
nobu e6be6ebc77 st.c: update the key too if changed
* st.c (st_update): fix a bug that the key was not updated even if
  it was changed by the callback function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-06 14:19:47 +00:00
nobu 6ab08d2e8d configure.in, missing.h: jemalloc mangling
* configure.in (with-jemalloc): also check for header, for ABIs
  which JEMALLOC_MANGLE is needed, i.e., Mach-O and PE-COFF
  platforms.  [ruby-core:62939] [Feature #9113]
* include/ruby/missing.h: include alternative malloc header to
  replace memory management functions.
* dln.c, io.c, parse.y, st.c: undef malloc family before
  re-definition to suppress warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-05 05:16:46 +00:00
tarui c94cb8b805 * st.c (st_foreach_check): chnage start point of search at check
from top to current. [ruby-dev:48047] [Bug #9646]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-20 03:58:22 +00:00
normal 8125399c09 st.c (st_init_table_with_size): update comment
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-31 01:34:19 +00:00
normal ef59670a44 st.c: use power-of-two sizes to avoid slow modulo ops
* st.c (hash_pos): use bitwise AND to avoid slow modulo op
  (new_size): power-of-two sizes for hash_pos change
  (st_numhash): adjust for common keys due to lack of prime modulo
  [Feature #9425]
* hash.c (rb_any_hash): right shift for symbols
* benchmark/bm_hash_aref_miss.rb: added to show improvement
* benchmark/bm_hash_aref_sym_long.rb: ditto
* benchmark/bm_hash_aref_str.rb: ditto
* benchmark/bm_hash_aref_sym.rb: ditto
* benchmark/bm_hash_ident_num.rb: added to prevent regression
* benchmark/bm_hash_ident_obj.rb: ditto
* benchmark/bm_hash_ident_str.rb: ditto
* benchmark/bm_hash_ident_sym.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-22 23:34:21 +00:00
normal b50780eac0 * st.c (st_update): remove unnecessary assignment
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 22:25:48 +00:00
tarui de1f3c92e7 * st.c (st_foreach): fix type of hash. not st_data_t but st_index_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-04 11:51:53 +00:00
nobu 254add068a st.c: hash_pos
* st.c (hash_pos): extract mapping hash values to hash bins index.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-18 05:47:38 +00:00
duerst 737c7d816b st.c: tweaked comment
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 10:35:50 +00:00
glass 79e6336495 * st.c: add st_values() and st_values_check().
* include/ruby/st.h: add prototypes for above.

* hash.c (rb_hash_values): use st_values_check() for performance
 improvement if VALUE and st_data_t are compatible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-28 08:39:16 +00:00
glass 78cfcbc657 * st.c (st_keys): fix not to use Qundef in st.c.
* include/ruby/st.h: define modified prototype.

* hash.c (rb_hash_keys): use modified st_keys().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-28 08:15:26 +00:00
glass b426e1b1fa * st.c (st_keys): define st_keys(). it writes each key to buffer.
* hash.c (rb_hash_keys): use st_keys() for performance improvement
  if st_data_t and VALUE are compatible.

* st.h: define macro ST_DATA_COMPATIBLE_P() to predicate whether
  st_data_t and passed type are compatible.

* configure.in: check existence of builtin function to use in
  ST_DATA_COMPATIBLE_P().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 16:07:10 +00:00
nobu b0af0592fd hash.c, st.c: fix for ST_CHECK
* hash.c (foreach_safe_i, hash_foreach_iter): deal with error detected
  by ST_CHECK.
* st.c (st_foreach_check): call with non-error argument in normal case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-14 02:33:50 +00:00
nobu b28ce966c7 st.c: revert st_keys
* st.c: revert st_keys() at r43238.  VALUE cannot be in st.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 16:28:56 +00:00
glass 026955e375 * st.c (st_keys): define st_keys() for performance improvement of
Hash#keys and Array#uniq.

* st.h: ditto.

* hash.c (rb_hash_keys): use st_keys().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 12:06:01 +00:00
akr 8795574510 * st.c (st_locale_insensitive_strcasecmp): Renamed from st_strcasecmp.
(st_locale_insensitive_strncasecmp): Renamed from st_strncasecmp.

* include/ruby/st.h: Follow above changes.

* include/ruby/ruby.h: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 23:15:41 +00:00
glass 13a1fd6d82 * configure.in: revert r42008. strcasecmp() uses the current locale.
* include/ruby/ruby.h: ditto.

* st.c (st_strcasecmp): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 12:49:01 +00:00
glass a0d9bd4445 * configure.in: check strcasecmp().
* include/ruby/ruby.h: use strcasecmp() as st_strcasecmp() if it
  exists.

* st.c (st_strcasecmp): define the function only if strcasecmp()
  doesn't exist.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 12:13:19 +00:00
nobu 5a3fab5918 * st.c (st_shift): remove unused variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-25 05:25:53 +00:00
charliesome 5d7b5481ca * benchmark/bm_hash_shift.rb: add benchmark for Hash#shift
* hash.c (rb_hash_shift): use st_shift if hash is not being iterated to
  delete element without iterating the whole hash.

* hash.c (shift_i): remove function

* include/ruby/st.h (st_shift): add st_shift function

* st.c (st_shift): ditto

[Bug #8312] [ruby-core:54524] Patch by funny-falcon

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-25 05:03:30 +00:00
zzak ff6eb8fe9a Fixed comment typo, found by @ThePablick
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-19 14:32:29 +00:00
naruse 29f347af11 * regint.h: fix typo: _M_AMD86 -> _M_AMD64.
* siphash.c: ditto.

* st.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-10 21:16:44 +00:00
shirosaki 262cb379d6 st_update passes the key in st_table
* st.c (st_update): pass the key in st_table so that we can free
  memory of the key in st_table when deleting.
  [ruby-core:49220] [Bug #7330]

* test/-ext-/st/test_update.rb
  (Bug::StTable#test_pass_objects_in_st_table): add a test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-17 02:46:13 +00:00
nobu 94d0221df4 * st.c (st_foreach_check, st_foreach): remove ancient check. This
check are from initial ordered hash commit when first entry were
  created with entry->fore = entry->back = entry.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-31 01:13:26 +00:00
nobu 44e6f5a1bb * st.c (st_delete): use real_entries in st_delete for packed tables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-31 01:01:41 +00:00
nobu 197627354e * st.c (st_foreach_check): remove the entry by replacing with never
when ST_DELETE.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-30 22:53:26 +00:00
nobu 28cc4f7543 * st.c (st_update): pass pointer to key to the callback function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-29 14:50:20 +00:00
nobu 30cea65767 * st.c (st_update): add existing parameter to the callback function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-29 07:36:12 +00:00
nobu 3007acfbc6 * st.c: pack tables also generic keys. patched by Sokolov Yura at
https://github.com/ruby/ruby/pull/84


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-10 14:52:30 +00:00
nobu a73d958c33 * st.c: add st_foreach_check for fixing iteration over packed table
and st_delete_safe.  patched by Sokolov Yura at
  https://github.com/ruby/ruby/pull/84


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-10 14:52:19 +00:00
nobu efae619458 * st.c: fix packed num_entries on delete_safe. patched by Sokolov
Yura at https://github.com/ruby/ruby/pull/84


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-10 14:52:06 +00:00
nobu 4a6e738a46 * st.c (unpack_entries): chain entries directly. based on a patch
by Sokolov Yura <funny.falcon AT gmail.com>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-05 03:44:14 +00:00
nobu 4a8c531a26 * st.c (unpack_entries): use union instead of casted pointer.
patched by Sokolov Yura <funny.falcon AT gmail.com>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-05 03:44:05 +00:00
nobu 5bd91964b2 * st.c: use PACKED_ENT and FIND_ENTRY. patched by Sokolov
Yura <funny.falcon AT gmail.com>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-05 03:43:55 +00:00
nobu e5ac15998d * st.c (unpack_entries): reallocate bins if packed array size
is not same as initial bins size.  based on a patch by
  Sokolov Yura <funny.falcon AT gmail.com>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-05 03:43:45 +00:00
nobu 4a43f9203b * st.c: refactor packed entries using structs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-07 10:37:40 +00:00
nobu cf1a22fdf9 * st.c (st_update): table can be unpacked in the callback.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-07 05:52:15 +00:00
nobu 97c3c98762 * st.c (st_foreach): should not yield same pair when checking
after unpacking.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-07 05:29:20 +00:00
nobu e8590143a0 * st.c (add_packed_direct): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-17 02:40:42 +00:00
nobu 270ac46a7c * st.c (do_hash): it's the time to remove cast to unsigned int.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-17 01:54:50 +00:00
naruse 84f204046b * st.c (unpack_entries): Fix r34310: on unpacking, the position of
a hash must be do_hash-ed value.

* st.c (add_packed_direct): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-16 22:38:05 +00:00
shyouhei d3f8488b1c st optimize st_insert
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-15 15:46:44 +00:00
shyouhei 9ed8c1f15e st refactor add_packed_direct a bit
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-15 15:46:41 +00:00