[m-rev.] diff: more efficient string.remove_suffix

Peter Wang novalazy at gmail.com
Thu Jun 26 13:07:37 AEST 2008


Estimated hours taken: 0.1
Branches: main

library/string.m:
	Replace `string.remove_suffix' by a version that doesn't create
	intermediate character lists.

Index: library/string.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.272
diff -u -p -r1.272 string.m
--- library/string.m	28 Apr 2008 05:13:05 -0000	1.272
+++ library/string.m	26 Jun 2008 03:00:24 -0000
@@ -1074,10 +1074,8 @@ string.right(String, RightCount, RightSt
     string.split(String, LeftCount, _LeftString, RightString).
 
 string.remove_suffix(A, B, C) :-
-    string.to_char_list(A, LA),
-    string.to_char_list(B, LB),
-    string.to_char_list(C, LC),
-    char_list_remove_suffix(LA, LB, LC).
+    string.suffix(A, B),
+    string.left(A, length(A) - length(B), C).
 
 string.remove_suffix_if_present(Suffix, String) = Out :-
     LeftCount = length(String) - length(Suffix),


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list