[m-rev.] for review: implement io__read_file_as_string on il backend
Peter Ross
pro at missioncriticalit.com
Wed Dec 4 20:41:17 AEDT 2002
On Wed, Dec 04, 2002 at 11:35:09AM +1100, Fergus Henderson wrote:
> With the current implementation, which for .NET does not optimize no-tag
> types, it would be more efficient to avoid constructing buffer/1 values at
> each iteration of the loop.
>
Done.
> Also, you could use array__unsafe_set here
> (which on .NET is in fact range-checked anyway).
>
unsafe_set is local to the array modle.
>
> Also, it would be more efficient to use a char_array type, which could be
> defined in C# as char[], rather than array(char). For Java or .NET-style
> implementations of array, this would be faster, since indexing into
> an array whose element type is known statically avoids some overhead
> that is required when the element type isn't determined statically.
> (For C-style implementations of array, char_array could use a lot less
> memory than array(char).) The current implementation is OK for now,
> but it would be good to have an XXX comment about this.
>
diff -u io.m io.m
--- io.m
+++ io.m
@@ -2087,6 +2087,11 @@
:- type buffer.
:- pragma foreign_type(c, buffer, "MR_Char *").
+
+ % XXX It would be better to use a char_array (e.g. defined as char[] in
+ % C#) type rather than array(char). This is because on the Java and IL
+ % backends indexing into an array whose element type is known
+ % statically requires less overhead.
:- type buffer ---> buffer(array(char)).
% XXX Extend the workaround for no `ui' modes in array.m.
@@ -2200,6 +2205,13 @@
}").
io__read_into_buffer(Stream, buffer(Array0), Pos0, Size, buffer(Array), Pos) -->
+ io__read_into_array(Stream, Array0, Pos0, Size, Array, Pos).
+
+:- pred io__read_into_array(stream::in, array(char)::array_di, int::in, int::in,
+ array(char)::array_uo, int::out,
+ io__state::di, io__state::uo) is det.
+
+io__read_into_array(Stream, Array0, Pos0, Size, Array, Pos) -->
( { Pos0 >= Size } ->
{ Array = Array0 },
{ Pos = Pos0 }
@@ -2207,8 +2219,8 @@
io__read_char(Stream, CharResult),
( { CharResult = ok(Char) } ->
{ array__set(Array0, Pos0, Char, Array1) },
- io__read_into_buffer(Stream, buffer(Array1), Pos0 + 1,
- Size, buffer(Array), Pos)
+ io__read_into_array(Stream, Array1, Pos0 + 1,
+ Size, Array, Pos)
;
{ Array = Array0 },
{ Pos = Pos0}
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list