Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
facf5f99
Commit
facf5f99
authored
Jul 31, 2017
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jul 31, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3758 from christopheraue/enumeration_perf
Improved speed of enumeration methods
parents
c8fdab87
3359b86e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
48 deletions
+49
-48
mrbgems/mruby-array-ext/mrblib/array.rb
mrbgems/mruby-array-ext/mrblib/array.rb
+8
-8
mrbgems/mruby-enumerator/mrblib/enumerator.rb
mrbgems/mruby-enumerator/mrblib/enumerator.rb
+10
-9
mrbgems/mruby-hash-ext/mrblib/hash.rb
mrbgems/mruby-hash-ext/mrblib/hash.rb
+8
-8
mrblib/array.rb
mrblib/array.rb
+3
-3
mrblib/hash.rb
mrblib/hash.rb
+15
-15
mrblib/numeric.rb
mrblib/numeric.rb
+4
-4
mrblib/range.rb
mrblib/range.rb
+1
-1
No files found.
mrbgems/mruby-array-ext/mrblib/array.rb
View file @
facf5f99
...
...
@@ -252,7 +252,7 @@ class Array
# for efficiency
def
reverse_each
(
&
block
)
return
to_enum
:reverse_each
unless
block
_given?
return
to_enum
:reverse_each
unless
block
i
=
self
.
size
-
1
while
i
>=
0
...
...
@@ -474,7 +474,7 @@ class Array
# scores.delete_if {|score| score < 80 } #=> [97]
def
delete_if
(
&
block
)
return
to_enum
:delete_if
unless
block
_given?
return
to_enum
:delete_if
unless
block
idx
=
0
while
idx
<
self
.
size
do
...
...
@@ -503,7 +503,7 @@ class Array
# If no block is given, an Enumerator is returned instead.
def
reject!
(
&
block
)
return
to_enum
:reject!
unless
block
_given?
return
to_enum
:reject!
unless
block
len
=
self
.
size
idx
=
0
...
...
@@ -593,7 +593,7 @@ class Array
# undefined which value is actually picked up at each iteration.
def
bsearch
(
&
block
)
return
to_enum
:bsearch
unless
block
_given?
return
to_enum
:bsearch
unless
block
if
idx
=
bsearch_index
(
&
block
)
self
[
idx
]
...
...
@@ -615,7 +615,7 @@ class Array
# element itself. For more details consult the documentation for #bsearch.
def
bsearch_index
(
&
block
)
return
to_enum
:bsearch_index
unless
block
_given?
return
to_enum
:bsearch_index
unless
block
low
=
0
high
=
size
...
...
@@ -667,7 +667,7 @@ class Array
# scores.delete_if {|score| score < 80 } #=> [97]
def
delete_if
(
&
block
)
return
to_enum
:delete_if
unless
block
_given?
return
to_enum
:delete_if
unless
block
idx
=
0
while
idx
<
self
.
size
do
...
...
@@ -696,7 +696,7 @@ class Array
# a.keep_if { |val| val > 3 } #=> [4, 5]
def
keep_if
(
&
block
)
return
to_enum
:keep_if
unless
block
_given?
return
to_enum
:keep_if
unless
block
idx
=
0
len
=
self
.
size
...
...
@@ -725,7 +725,7 @@ class Array
# If no block is given, an Enumerator is returned instead.
def
select!
(
&
block
)
return
to_enum
:select!
unless
block
_given?
return
to_enum
:select!
unless
block
result
=
[]
self
.
each
do
|
x
|
...
...
mrbgems/mruby-enumerator/mrblib/enumerator.rb
View file @
facf5f99
...
...
@@ -110,7 +110,7 @@ class Enumerator
# p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
#
def
initialize
(
obj
=
nil
,
meth
=
:each
,
*
args
,
&
block
)
if
block
_given?
if
block
obj
=
Generator
.
new
(
&
block
)
else
raise
ArgumentError
unless
obj
...
...
@@ -151,8 +151,9 @@ class Enumerator
#
# +offset+:: the starting index to use
#
def
with_index
(
offset
=
0
)
return
to_enum
:with_index
,
offset
unless
block_given?
def
with_index
(
offset
=
0
,
&
block
)
return
to_enum
:with_index
,
offset
unless
block
offset
=
if
offset
.
nil?
0
elsif
offset
.
respond_to?
(
:to_int
)
...
...
@@ -164,7 +165,7 @@ class Enumerator
n
=
offset
-
1
enumerator_block_call
do
|*
i
|
n
+=
1
yield
i
.
__svalue
,
n
block
.
call
i
.
__svalue
,
n
end
end
...
...
@@ -209,11 +210,11 @@ class Enumerator
# # => foo:1
# # => foo:2
#
def
with_object
(
object
)
return
to_enum
(
:with_object
,
object
)
unless
block
_given?
def
with_object
(
object
,
&
block
)
return
to_enum
(
:with_object
,
object
)
unless
block
enumerator_block_call
do
|
i
|
yield
[
i
,
object
]
block
.
call
[
i
,
object
]
end
object
end
...
...
@@ -277,7 +278,7 @@ class Enumerator
end
obj
.
args
=
args
end
return
obj
unless
block
_given?
return
obj
unless
block
enumerator_block_call
(
&
block
)
end
...
...
@@ -538,7 +539,7 @@ class Enumerator
# just for internal
class
Yielder
def
initialize
(
&
block
)
raise
LocalJumpError
,
"no block given"
unless
block
_given?
raise
LocalJumpError
,
"no block given"
unless
block
@proc
=
block
end
...
...
mrbgems/mruby-hash-ext/mrblib/hash.rb
View file @
facf5f99
...
...
@@ -171,7 +171,7 @@ class Hash
#
def
delete_if
(
&
block
)
return
to_enum
:delete_if
unless
block
_given?
return
to_enum
:delete_if
unless
block
self
.
each
do
|
k
,
v
|
self
.
delete
(
k
)
if
block
.
call
(
k
,
v
)
...
...
@@ -228,7 +228,7 @@ class Hash
#
def
keep_if
(
&
block
)
return
to_enum
:keep_if
unless
block
_given?
return
to_enum
:keep_if
unless
block
keys
=
[]
self
.
each
do
|
k
,
v
|
...
...
@@ -393,11 +393,11 @@ class Hash
#
# If no block is given, an enumerator is returned instead.
#
def
transform_keys
(
&
b
)
return
to_enum
:transform_keys
unless
block
_given?
def
transform_keys
(
&
b
lock
)
return
to_enum
:transform_keys
unless
block
hash
=
{}
self
.
keys
.
each
do
|
k
|
new_key
=
yield
(
k
)
new_key
=
block
.
call
(
k
)
hash
[
new_key
]
=
self
[
k
]
end
hash
...
...
@@ -412,11 +412,11 @@ class Hash
#
# If no block is given, an enumerator is returned instead.
#
def
transform_keys!
(
&
b
)
return
to_enum
:transform_keys!
unless
block
_given?
def
transform_keys!
(
&
b
lock
)
return
to_enum
:transform_keys!
unless
block
self
.
keys
.
each
do
|
k
|
value
=
self
[
k
]
new_key
=
yield
(
k
)
new_key
=
block
.
call
(
k
)
self
.
__delete
(
k
)
self
[
new_key
]
=
value
end
...
...
mrblib/array.rb
View file @
facf5f99
...
...
@@ -11,7 +11,7 @@ class Array
#
# ISO 15.2.12.5.10
def
each
(
&
block
)
return
to_enum
:each
unless
block
_given?
return
to_enum
:each
unless
block
idx
=
0
while
idx
<
length
...
...
@@ -27,7 +27,7 @@ class Array
#
# ISO 15.2.12.5.11
def
each_index
(
&
block
)
return
to_enum
:each_index
unless
block
_given?
return
to_enum
:each_index
unless
block
idx
=
0
while
idx
<
length
...
...
@@ -44,7 +44,7 @@ class Array
#
# ISO 15.2.12.5.7
def
collect!
(
&
block
)
return
to_enum
:collect!
unless
block
_given?
return
to_enum
:collect!
unless
block
self
.
each_index
{
|
idx
|
self
[
idx
]
=
block
.
call
(
self
[
idx
])
}
self
...
...
mrblib/hash.rb
View file @
facf5f99
...
...
@@ -84,7 +84,7 @@ class Hash
#
# ISO 15.2.13.4.9
def
each
(
&
block
)
return
to_enum
:each
unless
block
_given?
return
to_enum
:each
unless
block
keys
=
self
.
keys
vals
=
self
.
values
...
...
@@ -117,7 +117,7 @@ class Hash
#
# ISO 15.2.13.4.10
def
each_key
(
&
block
)
return
to_enum
:each_key
unless
block
_given?
return
to_enum
:each_key
unless
block
self
.
keys
.
each
{
|
k
|
block
.
call
(
k
)}
self
...
...
@@ -143,7 +143,7 @@ class Hash
#
# ISO 15.2.13.4.11
def
each_value
(
&
block
)
return
to_enum
:each_value
unless
block
_given?
return
to_enum
:each_value
unless
block
self
.
keys
.
each
{
|
k
|
block
.
call
(
self
[
k
])}
self
...
...
@@ -224,12 +224,12 @@ class Hash
#
# 1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
#
def
reject!
(
&
b
)
return
to_enum
:reject!
unless
block
_given?
def
reject!
(
&
b
lock
)
return
to_enum
:reject!
unless
block
keys
=
[]
self
.
each
{
|
k
,
v
|
if
b
.
call
([
k
,
v
])
if
b
lock
.
call
([
k
,
v
])
keys
.
push
(
k
)
end
}
...
...
@@ -255,12 +255,12 @@ class Hash
#
# 1.8/1.9 Hash#reject returns Hash; ISO says nothing.
#
def
reject
(
&
b
)
return
to_enum
:reject
unless
block
_given?
def
reject
(
&
b
lock
)
return
to_enum
:reject
unless
block
h
=
{}
self
.
each
{
|
k
,
v
|
unless
b
.
call
([
k
,
v
])
unless
b
lock
.
call
([
k
,
v
])
h
[
k
]
=
v
end
}
...
...
@@ -277,12 +277,12 @@ class Hash
#
# 1.9 Hash#select! returns Hash; ISO says nothing.
#
def
select!
(
&
b
)
return
to_enum
:select!
unless
block
_given?
def
select!
(
&
b
lock
)
return
to_enum
:select!
unless
block
keys
=
[]
self
.
each
{
|
k
,
v
|
unless
b
.
call
([
k
,
v
])
unless
b
lock
.
call
([
k
,
v
])
keys
.
push
(
k
)
end
}
...
...
@@ -308,12 +308,12 @@ class Hash
#
# 1.9 Hash#select returns Hash; ISO says nothing
#
def
select
(
&
b
)
return
to_enum
:select
unless
block
_given?
def
select
(
&
b
lock
)
return
to_enum
:select
unless
block
h
=
{}
self
.
each
{
|
k
,
v
|
if
b
.
call
([
k
,
v
])
if
b
lock
.
call
([
k
,
v
])
h
[
k
]
=
v
end
}
...
...
mrblib/numeric.rb
View file @
facf5f99
...
...
@@ -45,7 +45,7 @@ module Integral
#
# ISO 15.2.8.3.15
def
downto
(
num
,
&
block
)
return
to_enum
(
:downto
,
num
)
unless
block
_given?
return
to_enum
(
:downto
,
num
)
unless
block
i
=
self
.
to_i
while
i
>=
num
...
...
@@ -70,7 +70,7 @@ module Integral
#
# ISO 15.2.8.3.22
def
times
&
block
return
to_enum
:times
unless
block
_given?
return
to_enum
:times
unless
block
i
=
0
while
i
<
self
...
...
@@ -86,7 +86,7 @@ module Integral
#
# ISO 15.2.8.3.27
def
upto
(
num
,
&
block
)
return
to_enum
(
:upto
,
num
)
unless
block
_given?
return
to_enum
(
:upto
,
num
)
unless
block
i
=
self
.
to_i
while
i
<=
num
...
...
@@ -102,7 +102,7 @@ module Integral
#
def
step
(
num
=
nil
,
step
=
1
,
&
block
)
raise
ArgumentError
,
"step can't be 0"
if
step
==
0
return
to_enum
(
:step
,
num
,
step
)
unless
block
_given?
return
to_enum
(
:step
,
num
,
step
)
unless
block
i
=
if
num
.
kind_of?
Float
then
self
.
to_f
else
self
end
if
num
==
nil
...
...
mrblib/range.rb
View file @
facf5f99
...
...
@@ -10,7 +10,7 @@ class Range
#
# ISO 15.2.14.4.4
def
each
(
&
block
)
return
to_enum
:each
unless
block
_given?
return
to_enum
:each
unless
block
val
=
self
.
first
last
=
self
.
last
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment