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
082882da
Unverified
Commit
082882da
authored
Aug 31, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
string.rb: avoid internal `__to_str` calls.
`__to_str` was a mere type check method despite its name.
parent
8c296a38
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
16 deletions
+9
-16
mrblib/string.rb
mrblib/string.rb
+9
-16
No files found.
mrblib/string.rb
View file @
082882da
...
...
@@ -43,12 +43,12 @@ class String
end
# private method for gsub/sub
def
__sub_replace
(
pre
,
m
,
post
)
def
__sub_replace
(
rep
,
pre
,
m
,
post
)
s
=
""
i
=
0
while
j
=
index
(
"
\\
"
,
i
)
break
if
j
==
length
-
1
t
=
case
self
[
j
+
1
]
while
j
=
rep
.
index
(
"
\\
"
,
i
)
break
if
j
==
rep
.
length
-
1
t
=
case
rep
[
j
+
1
]
when
"
\\
"
"
\\
"
when
"`"
...
...
@@ -60,12 +60,12 @@ class String
when
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
""
else
self
[
j
,
2
]
rep
[
j
,
2
]
end
s
+=
self
[
i
,
j
-
i
]
+
t
s
+=
rep
[
i
,
j
-
i
]
+
t
i
=
j
+
2
end
s
+
self
[
i
,
length
-
i
]
s
+
rep
[
i
,
rep
.
length
-
i
]
end
##
...
...
@@ -84,9 +84,6 @@ class String
if
args
.
length
==
2
&&
block
block
=
nil
end
if
!
replace
.
nil?
||
!
block
replace
.
__to_str
end
offset
=
0
result
=
[]
while
found
=
index
(
pattern
,
offset
)
...
...
@@ -95,7 +92,7 @@ class String
result
<<
if
block
block
.
call
(
pattern
).
to_s
else
replace
.
__sub_replace
(
self
[
0
,
found
],
pattern
,
self
[
offset
..-
1
]
||
""
)
__sub_replace
(
replace
,
self
[
0
,
found
],
pattern
,
self
[
offset
..-
1
]
||
""
)
end
if
plen
==
0
result
<<
self
[
offset
,
1
]
...
...
@@ -144,13 +141,9 @@ class String
end
pattern
,
replace
=
*
args
pattern
.
__to_str
if
args
.
length
==
2
&&
block
block
=
nil
end
unless
block
replace
.
__to_str
end
result
=
[]
this
=
dup
found
=
index
(
pattern
)
...
...
@@ -160,7 +153,7 @@ class String
result
<<
if
block
block
.
call
(
pattern
).
to_s
else
replace
.
__sub_replace
(
this
[
0
,
found
],
pattern
,
this
[
offset
..-
1
]
||
""
)
__sub_replace
(
replace
,
this
[
0
,
found
],
pattern
,
this
[
offset
..-
1
]
||
""
)
end
result
<<
this
[
offset
..-
1
]
if
offset
<
length
result
.
join
...
...
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