[m-rev.] diff: optimise get_type_ctor_rep for java

Peter Wang novalazy at gmail.com
Mon Mar 15 15:02:26 AEDT 2010


Branches: main, 10.04

library/rtti_implementation.m:
        Make Java version of get_type_ctor_rep return preallocated values.

library/private_builtin.m:
        Add a constant which counts the number of MR_TYPECTOR_REP_* values.

diff --git a/library/private_builtin.m b/library/private_builtin.m
index f456a18..abf76ea 100644
--- a/library/private_builtin.m
+++ b/library/private_builtin.m
@@ -1652,7 +1652,8 @@ no_clauses(PredName) :-
     public static final int MR_TYPECTOR_REP_FOREIGN_ENUM            = 44;
     public static final int MR_TYPECTOR_REP_FOREIGN_ENUM_USEREQ     = 45;
     public static final int MR_TYPECTOR_REP_UNKNOWN                 = 46;
-    
+    public static final int MR_TYPECTOR_REP_MAX                     = 47;
+
     public static final int MR_SECTAG_NONE      = 0;
     public static final int MR_SECTAG_LOCAL     = 1;
     public static final int MR_SECTAG_REMOTE    = 2;
diff --git a/library/rtti_implementation.m b/library/rtti_implementation.m
index a19ad80..748a547 100644
--- a/library/rtti_implementation.m
+++ b/library/rtti_implementation.m
@@ -206,6 +206,17 @@
     import jmercury.runtime.TypeInfo_Struct;
 ").
 
+:- pragma foreign_code("Java",
+"
+    private static final Type_ctor_rep_0[] static_type_ctor_rep
+        = new Type_ctor_rep_0[private_builtin.MR_TYPECTOR_REP_MAX];
+    static {
+        for (int i = 0; i < private_builtin.MR_TYPECTOR_REP_MAX; i++) {
+            static_type_ctor_rep[i] = new Type_ctor_rep_0(i);
+        }
+    }
+").
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 %
@@ -3212,8 +3223,7 @@ type_ctor_compare_pred(_) = unify_or_compare_pred :-
     get_type_ctor_rep(TypeCtorInfo::in) = (TypeCtorRep::out),
     [will_not_call_mercury, promise_pure, thread_safe],
 "
-    // XXX this is called quite a lot so this might be inefficient
-    TypeCtorRep = new Type_ctor_rep_0(TypeCtorInfo.type_ctor_rep.value);
+    TypeCtorRep = static_type_ctor_rep[TypeCtorInfo.type_ctor_rep.value];
 ").
 :- pragma foreign_proc("C",
     get_type_ctor_rep(TypeCtorInfo::in) = (TypeCtorRep::out),

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