[m-rev.] diff: more efficient library functions for Erlang backend
Peter Wang
wangp at students.csse.unimelb.edu.au
Fri Jul 6 18:05:29 AEST 2007
Branches: main
library/list.m:
Override list.reverse with a more efficient version for Erlang.
library/string.m:
Add efficient implementations of semidet_from_char_list/2,
sub_string_search_start/4 and substring/4 for Erlang.
Index: library/list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.163
diff -u -r1.163 list.m
--- library/list.m 13 Feb 2007 00:16:57 -0000 1.163
+++ library/list.m 6 Jul 2007 08:01:35 -0000
@@ -1609,6 +1609,13 @@
list.reverse_2([X | Xs], L0, L) :-
list.reverse_2(Xs, [X | L0], L).
+:- pragma foreign_proc("Erlang",
+ list.reverse(L0::in, L::out),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ L = lists:reverse(L0)
+").
+
%-----------------------------------------------------------------------------%
list.sort(L0, L) :-
Index: library/string.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.261
diff -u -r1.261 string.m
--- library/string.m 6 Jun 2007 02:09:44 -0000 1.261
+++ library/string.m 6 Jul 2007 08:01:35 -0000
@@ -1356,6 +1356,15 @@
Str[size] = '\\0';
}").
+:- pragma foreign_proc("Erlang",
+ string.semidet_from_char_list(CharList::in, Str::uo),
+ [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
+ does_not_affect_liveness],
+"
+ Str = CharList,
+ SUCCESS_INDICATOR = true
+").
+
:- pragma promise_equivalent_clauses(string.semidet_from_char_list/2).
string.semidet_from_char_list(CharList::in, Str::uo) :-
@@ -1693,6 +1702,22 @@
SUCCESS_INDICATOR = (Index >= 0);
}").
+:- pragma foreign_proc("Erlang",
+ sub_string_search_start(WholeString::in, Pattern::in, BeginAt::in,
+ Index::out),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ String = lists:nthtail(BeginAt, WholeString),
+ case string:str(String, Pattern) of
+ 0 ->
+ Index = -1,
+ SUCCESS_INDICATOR = false;
+ Match ->
+ Index = BeginAt + Match - 1,
+ SUCCESS_INDICATOR = true
+ end
+").
+
% This is only used if there is no matching foreign_proc definition
sub_string_search_start(String, SubString, BeginAt, Index) :-
sub_string_search_start_2(String, SubString, BeginAt, length(String),
@@ -3988,6 +4013,24 @@
}
}").
+:- pragma foreign_proc("Erlang",
+ string.substring(Str::in, Start0::in, Count::in, SubString::uo),
+ [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
+ does_not_affect_liveness],
+"
+ Start =
+ if
+ Start0 < 0 -> 0;
+ true -> Start0
+ end,
+ if
+ Count =< 0 ->
+ SubString = """";
+ true ->
+ SubString = string:substr(Str, 1 + Start, Count)
+ end
+").
+
:- pragma foreign_proc("C",
string.unsafe_substring(Str::in, Start::in, Count::in, SubString::uo),
[will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
--------------------------------------------------------------------------
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