[m-dev.] for review: new string__length mode
Michael Day
mikeday at corplink.com.au
Thu Nov 16 21:12:01 AEDT 2000
For optimisation of string__length(LongString, SmallNumber). Anyone think
this is actually worth it?
Estimated hours taken: 0.25
library/string.m:
Added a new mode to string__length for checking if the length of a
string is equal to a particular number.
Index: string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.137
diff -u -r1.137 string.m
--- string.m 2000/11/16 05:29:31 1.137
+++ string.m 2000/11/16 09:03:57
@@ -26,6 +26,7 @@
:- pred string__length(string, int).
:- mode string__length(in, uo) is det.
:- mode string__length(ui, uo) is det.
+:- mode string__length(ui, in) is semidet.
% Determine the length of a string.
% An empty string has length zero.
@@ -1616,6 +1617,20 @@
:- pragma c_code(string__length(Str::ui, Length::uo),
[will_not_call_mercury, thread_safe], "
Length = strlen(Str);
+").
+
+/*
+:- pred string__length(string, int).
+:- mode string__length(ui, in) is semidet.
+*/
+:- pragma c_code(string__length(Str::ui, Length::in),
+ [will_not_call_mercury, thread_safe], "
+ size_t j;
+ char *Str2 = Str;
+ for (j = Length; j != 0; j--, Str2++) {
+ if (*Str2 == 0) break;
+ }
+ SUCCESS_INDICATOR = (*Str2 == 0 && j == 0);
").
/*-----------------------------------------------------------------------*/
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list