Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use replace instead of substr #1749

Closed
p6rt opened this issue May 6, 2010 · 4 comments
Closed

use replace instead of substr #1749

p6rt opened this issue May 6, 2010 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 6, 2010

Migrated from rt.perl.org#74942 (status was 'resolved')

Searchable as RT74942$

@p6rt
Copy link
Author

p6rt commented May 6, 2010

From @zhuomingliang

From 42acea630546f1641ae6914c459da53036b4e8c0 Mon Sep 17 00​:00​:00 2001
From​: Jimmy Zhuo <zhuomingliang@​yahoo.com.cn>
Date​: Thu, 6 May 2010 15​:51​:19 +0800
Subject​: use replace instead of substr


src/builtins/Str.pir | 20 ++++----------------
1 files changed, 4 insertions(+), 16 deletions(-)

Inline Patch
diff --git a/src/builtins/Str.pir b/src/builtins/Str.pir
index 7ba0230..2493b41 100644
--- a/src/builtins/Str.pir
+++ b/src/builtins/Str.pir
@@ -1,4 +1,4 @@
-=head1 TITLE
+=head1 TITLE
 
 Str - Perl 6 Str class and related functions
 
@@ -155,11 +155,7 @@ Increment and Decrement Methods
   dec_2:
     dec ipos
     repl = substr RANGES, ipos, 1
-    $S0 = substr str, 0, r1
-    $I0 = r1 + 1
-    $S1 = substr str, $I0
-    str = concat $S0, repl
-    str = concat str, $S1
+    str  = replace str, r1, 1, repl
     # if the replacement wasn't a carry, we're done
     if orig > repl goto done
   carry:
@@ -190,11 +186,7 @@ Increment and Decrement Methods
     inc ipos
     .local string repl
     repl = substr RANGES, ipos, 1
-        $S0 = substr str, 0, r1
-    $I0 = r1 + 1
-    $S1 = substr str, $I0
-    str = concat $S0, repl
-    str = concat str, $S1
+    str  = replace str, r1, 1, repl
     # if the replacement wasn't a carry, we're done
     if orig < repl goto done
   carry:
@@ -206,11 +198,7 @@ Increment and Decrement Methods
     unless repl == '0' goto extend_1
     repl = '1'
   extend_1:
-    $S0 = substr str, 0, r0
-    $S1 = substr str, r0
-    str = concat $S0, repl
-    str = concat str, $S1
-
+    str = replace str, r0, 0, repl
   done:
     .return (str)
 .end
-- 
1.6.4.msysgit.0

�此�你身��康�天天快�
��亮

 

@p6rt
Copy link
Author

p6rt commented May 6, 2010

From @zhuomingliang

0001-use-replace-instead-of-substr.patch
From 42acea630546f1641ae6914c459da53036b4e8c0 Mon Sep 17 00:00:00 2001
From: Jimmy Zhuo <zhuomingliang@yahoo.com.cn>
Date: Thu, 6 May 2010 15:51:19 +0800
Subject: use replace instead of substr

---
 src/builtins/Str.pir |   20 ++++----------------
 1 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/src/builtins/Str.pir b/src/builtins/Str.pir
index 7ba0230..2493b41 100644
--- a/src/builtins/Str.pir
+++ b/src/builtins/Str.pir
@@ -1,4 +1,4 @@
-=head1 TITLE
+���=head1 TITLE
 
 Str - Perl 6 Str class and related functions
 
@@ -155,11 +155,7 @@ Increment and Decrement Methods
   dec_2:
     dec ipos
     repl = substr RANGES, ipos, 1
-    $S0 = substr str, 0, r1
-    $I0 = r1 + 1
-    $S1 = substr str, $I0
-    str = concat $S0, repl
-    str = concat str, $S1
+    str  = replace str, r1, 1, repl
     # if the replacement wasn't a carry, we're done
     if orig > repl goto done
   carry:
@@ -190,11 +186,7 @@ Increment and Decrement Methods
     inc ipos
     .local string repl
     repl = substr RANGES, ipos, 1
-        $S0 = substr str, 0, r1
-    $I0 = r1 + 1
-    $S1 = substr str, $I0
-    str = concat $S0, repl
-    str = concat str, $S1
+    str  = replace str, r1, 1, repl
     # if the replacement wasn't a carry, we're done
     if orig < repl goto done
   carry:
@@ -206,11 +198,7 @@ Increment and Decrement Methods
     unless repl == '0' goto extend_1
     repl = '1'
   extend_1:
-    $S0 = substr str, 0, r0
-    $S1 = substr str, r0
-    str = concat $S0, repl
-    str = concat str, $S1
-
+    str = replace str, r0, 0, repl
   done:
     .return (str)
 .end
-- 
1.6.4.msysgit.0

@p6rt
Copy link
Author

p6rt commented May 11, 2010

From @moritz

Applied, thanks.

@p6rt
Copy link
Author

p6rt commented May 11, 2010

@moritz - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed May 11, 2010
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant