diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-09-26 11:14:36 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-09-26 23:09:48 +0900 |
| commit | d78acc7afed35813f25e3091150dab668c373f05 (patch) | |
| tree | 5d9c5651b8b00aa2f7f3245817d67dd3662b4ab3 /mrbgems/mruby-array-ext | |
| parent | 8ffd4e47fb1c18088e554d31e8af88881517a201 (diff) | |
| download | mruby-d78acc7afed35813f25e3091150dab668c373f05.tar.gz mruby-d78acc7afed35813f25e3091150dab668c373f05.zip | |
Add index to larger segment lists for performance
Diffstat (limited to 'mrbgems/mruby-array-ext')
| -rw-r--r-- | mrbgems/mruby-array-ext/mrblib/array.rb | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index 8c2acc7ac..eac8d4718 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -1,3 +1,4 @@ +# coding: cp932 class Array ## # call-seq: @@ -41,26 +42,19 @@ class Array # c.uniq! { |s| s.first } # => [["student", "sam"], ["teacher", "matz"]] # def uniq!(&block) + hash = {} if block - hash = {} self.each do |val| key = block.call(val) hash[key] = val unless hash.key?(key) end result = hash.values - elsif self.size > 20 + else hash = {} self.each do |val| hash[val] = val end - result = hash.values - else - ary = self.dup - result = [] - while ary.size > 0 - result << ary.shift - ary.delete(result.last) - end + result = hash.keys end if result.size == self.size nil |
