[m-rev.] for review: optimize calls to string.format and related predicates

Peter Wang novalazy at gmail.com
Thu Sep 3 08:24:46 AEST 2009


On 2009-09-02, Zoltan Somogyi <zs at csse.unimelb.edu.au> wrote:
> Besides a review of the change itself, I am seeking feedback on what
> exactly the optimization should do.
> 
> For optimizing e.g. io.format("%d_%d", [i(X), i(Y), !IO), this diff currently
> generates
> 
> 	V1 = int_to_string(X),
> 	V2 = "_"
> 	V3 = V2 ++ V1
> 	V4 = int_to_string(Y),
> 	V5 = V4 ++ V3
> 	io.write_string(V5, !IO)
> 
> Should it instead generate
> 
> 	V1 = int_to_string(X),
> 	io.write_string(V1, !IO),
> 	V2 = "_"
> 	io.write_string(V2, !IO),
> 	V3 = int_to_string(Y),
> 	io.write_string(V3, !IO)
> 
> This avoids memory allocation, but it requires more overheads in the I/O
> system, e.g. retrievals of the current output stream. What do you think?

Why not:

	io.output_stream(Stream, !IO),
	io.write_int(Stream, X, !IO),
	io.write_string(Stream, "_", !IO),
	io.write_int(Stream, Y, !IO)

Peter
--------------------------------------------------------------------------
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