[m-rev.] diff: use cached boxed values in java

Peter Wang novalazy at gmail.com
Tue May 11 13:08:06 AEST 2010


Branches: main, 10.04

compiler/mlds_to_java.m:
        Use valueOf methods to get boxed values of builtin types.  valueOf
        may return cached instances instead of creating new objects.

diff --git a/compiler/mlds_to_java.m b/compiler/mlds_to_java.m
index 47d136d..dfa87a0 100644
--- a/compiler/mlds_to_java.m
+++ b/compiler/mlds_to_java.m
@@ -4473,9 +4473,8 @@ have_preallocated_pseudo_type_var(N) :-
 
 output_boxed_rval(Info, Type, Expr, !IO) :-
     ( java_builtin_type(Type, _JavaName, JavaBoxedName, _) ->
-        io.write_string("new ", !IO),
         io.write_string(JavaBoxedName, !IO),
-        io.write_string("(", !IO),
+        io.write_string(".valueOf(", !IO),
         output_rval(Info, Expr, !IO),
         io.write_string(")", !IO)
     ;

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