2002-02-19 Radek Doulik <rodo@ximian.com>
authorRadek Doulik <rodo@mono-cvs.ximian.com>
Tue, 19 Feb 2002 21:34:40 +0000 (21:34 -0000)
committerRadek Doulik <rodo@mono-cvs.ximian.com>
Tue, 19 Feb 2002 21:34:40 +0000 (21:34 -0000)
* object.c (mono_ldstr): use hash table to avoid multiple swapping

svn path=/trunk/mono/; revision=2528

mono/metadata/ChangeLog
mono/metadata/object.c

index c03d742d51e39b2a7a77eb6d4da339c69ecb1e93..628e72739687d8fab5986f7371bc67c9bfcce3a1 100644 (file)
@@ -1,3 +1,6 @@
+2002-02-19  Radek Doulik  <rodo@ximian.com>
+
+       * object.c (mono_ldstr): use hash table to avoid multiple swapping
 
 Tue Feb 19 20:23:11 CET 2002 Paolo Molaro <lupus@ximian.com>
 
index 887f656fa0d0036df2856c95c3b5525f5fe5e07f..575589762e23e3783c77ebd0209956edd3b87109 100644 (file)
@@ -434,15 +434,24 @@ mono_ldstr (MonoDomain *domain, MonoImage *image, guint32 index)
        {
                gint i;
                guint16 *s;
-
-               /* FIXME: it will be better to just add WRITE and after get it to previous state */
-               mprotect ((void *) ((int) str & ~(PAGESIZE - 1)), len2 + ((int) str & (PAGESIZE - 1)),
-                                   PROT_READ | PROT_WRITE | PROT_EXEC);
-               len2 >>= 1;
-               /* printf ("swap %p\n", str); */
-               for (i = 0, s = (guint16 *) str; i < len2; i++, s++) {
-                       *s = ((*s & 0xff) << 8) | (*s >> 8);
-               }
+               /* FIXME: we need to find better way for swapping strings, i.e. swap all string after image load */
+               static GHashTable *converted_strings = NULL;
+
+               if (!converted_strings)
+                       converted_strings = g_hash_table_new (g_str_hash, g_str_equal);
+
+               if (converted_strings && !g_hash_table_lookup (converted_strings, str)) {
+                       /* FIXME: it will be better to just add WRITE and after get it to previous state */
+                       mprotect ((void *) ((int) str & ~(PAGESIZE - 1)), len2 + ((int) str & (PAGESIZE - 1)),
+                                 PROT_READ | PROT_WRITE | PROT_EXEC);
+                       len2 >>= 1;
+                       /* printf ("swap %p\n", str); */
+                       for (i = 0, s = (guint16 *) str; i < len2; i++, s++) {
+                               *s = ((*s & 0xff) << 8) | (*s >> 8);
+                       }
+                       g_hash_table_insert (converted_strings, (gpointer) str, (gpointer) str);
+               } else
+                       len2 >>= 1;
        }
 #undef SWAP16
 #else