--- src/g_netlist.c.orig	2005-01-23 18:24:57.000000000 +0100
+++ src/g_netlist.c	2005-01-23 18:11:44.000000000 +0100
@@ -40,34 +40,46 @@
 }
 
 
+static void
+hash_table_2_list (gpointer key,
+                   gpointer value,
+                   gpointer user_data)
+{
+  SCM* plist = (SCM*)user_data;
+
+  *plist = gh_cons(gh_str2scm((char*)value,
+                              strlen ((char*)value)),
+                   *plist);
+}
+
 /* this function will only return a unique list of packages */
 SCM g_get_packages(SCM level)
 {
     SCM list = SCM_EOL;
+    GHashTable *ht;
 
     NETLIST *nl_current = NULL;
 
     SCM_ASSERT( (SCM_NIMP (level) && SCM_STRINGP (level) ),
 		level, SCM_ARG1, "gnetlist:get-pins");
 
-    nl_current = netlist_head;
-    s_scratch_string_init();
-
-    while (nl_current != NULL) {
-
-	if (nl_current->component_uref) {
-	    if (s_scratch_string_fill(nl_current->component_uref)) {
-		list = gh_cons(gh_str2scm(nl_current->component_uref,
-					  strlen
-					  (nl_current->component_uref)),
-			       list);
-	    }
-	}
-	nl_current = nl_current->next;
+    /* build a hash table */
+    ht = g_hash_table_new (g_str_hash, g_str_equal);
+    for (nl_current = netlist_head; nl_current != NULL;
+         nl_current = nl_current->next) {
+      if (nl_current->component_uref != NULL) {
+        /* add component_uref in the hash table */
+        /* uniqueness of component_uref is guaranteed by the hashtable */
+        g_hash_table_insert (ht,
+                             nl_current->component_uref,
+                             nl_current->component_uref);
+      }
     }
+    /* now create a scheme list of the entries in the hash table */
+    g_hash_table_foreach (ht, hash_table_2_list, &list);
+    g_hash_table_destroy (ht);
 
-    s_scratch_string_free();
-    return (list);
+    return list;
 }
 
 /* this function will only return a non unique list of packages */
@@ -80,23 +92,15 @@
     SCM_ASSERT( (SCM_NIMP (level) && SCM_STRINGP (level) ),
 		level, SCM_ARG1, "gnetlist:get-pins");
 
-    nl_current = netlist_head;
-    s_scratch_string_init();
-
-    while (nl_current != NULL) {
-
-	if (nl_current->component_uref) {
-	    if (s_scratch_non_unique_string_fill(nl_current->component_uref)) {
-		list = gh_cons(gh_str2scm(nl_current->component_uref,
-					  strlen
-					  (nl_current->component_uref)),
-			       list);
-	    }
-	}
-	nl_current = nl_current->next;
+    for (nl_current = netlist_head; nl_current != NULL;
+         nl_current = nl_current->next) {
+      if (nl_current->component_uref != NULL) {
+        list = gh_cons (gh_str2scm (nl_current->component_uref,
+                                    strlen (nl_current->component_uref)),
+                        list);
+      }
     }
 
-    s_scratch_string_free();
     return (list);
 }
 
