2000-11-25
2000-11-25 16:45:02 by Henrik Grubbström (Grubba) <grubba@grubba.org>
-
6633f5f43da06ef71081f36ae312d9ef2a4556bc
(65 lines)
(+50/-15)
[
Show
| Annotate
]
Branch: 7.9
Optimized sub_node(), freeze_node() and free_all_nodes().
Also made some optimizations in mknode().
Rev: src/las.c:1.223
5:
\*/
/**/
#include "global.h"
- RCSID("$Id: las.c,v 1.222 2000/11/20 01:20:25 mast Exp $");
+ RCSID("$Id: las.c,v 1.223 2000/11/25 16:45:02 grubba Exp $");
#include "language.h"
#include "interpret.h"
400: Inside #if defined(SHARED_NODES)
{
node *prior;
+ #ifdef PIKE_DEBUG
if (!node_hash.size) {
return;
}
-
+ #endif /* PIKE_DEBUG */
prior = node_hash.table[n->hash % node_hash.size];
427: Inside #if defined(SHARED_NODES)
{
size_t hash = hash_node(orig);
node *n;
+ int found = 0;
/* free_node() wants a correct hash */
orig->hash = hash;
- if (orig->node_info & OPT_NOT_SHARED) {
+ if (orig->tree_info & OPT_NOT_SHARED) {
/* No need to have this node in the hash-table. */
/* add_node(orig); */
return check_node_hash(dmalloc_touch(node *, orig));
440: Inside #if defined(SHARED_NODES)
/* Mark this node as a possible duplicate */
orig->node_info |= OPT_DEFROSTED;
/* Make sure we don't find ourselves */
- sub_node(orig);
+ /* sub_node(orig); */
n = node_hash.table[hash % node_hash.size];
while (n) {
-
+ if (n == orig) {
+ found = 1;
+ if (!(n = n->next)) {
+ break;
+ }
+ }
if ((n->hash == hash) &&
!MEMCMP(&(n->token), &(orig->token),
sizeof(node) - OFFSETOF(node_s, token))) {
460: Inside #if defined(SHARED_NODES)
copy_shared_string(n->type, orig->type);
}
}
+ if (!found) {
+ node *scan = n;
+ while(scan->next) {
+ if (scan->next == orig) {
+ scan->next = orig->next;
+ break;
+ }
+ scan = scan->next;
+ }
+ } else {
+ /* FIXME: sub_node() recalculates the hash index.
+ * We might get better performance by using the one we already have.
+ */
+ sub_node(orig);
+ }
free_node(dmalloc_touch(node *, orig));
n->refs++;
return check_node_hash(dmalloc_touch(node *, n));
467: Inside #if defined(SHARED_NODES)
n = n->next;
}
orig->node_info &= ~OPT_DEFROSTED;
+ if (!found) {
add_node(dmalloc_touch(node *, orig));
-
+ }
check_tree(orig,0);
return check_node_hash(orig);
}
531:
#endif
{
/* Free the node and be happy */
+ #ifdef SHARED_NODES
+ /* Force the hashtable to be cleared. */
+ tmp->next = NULL;
+ sub_node(tmp);
+ #endif /* SHARED_NODES */
/* Make sure we don't free any nodes twice */
if(car_is_node(tmp)) _CAR(tmp)=0;
if(cdr_is_node(tmp)) _CDR(tmp)=0;
563:
cumulative_parse_error=0;
#ifdef SHARED_NODES
- MEMSET(node_hash.table, 0, sizeof(node *) * node_hash.size);
+ /* MEMSET(node_hash.table, 0, sizeof(node *) * node_hash.size); */
#endif /* SHARED_NODES */
}
}
816:
res->token = token;
res->type = 0;
- #ifdef SHARED_NODES
- {
- node *res2 = freeze_node(res);
-
- if (res2 != res) {
- return dmalloc_touch(node *, res2);
- }
- }
- #endif /* SHARED_NODES */
-
+
switch(token)
{
case F_CATCH:
978:
res->tree_info |= res->node_info;
+ #ifdef SHARED_NODES
+ /* No need to freeze the node if it can't be shared. */
+ if (!(res->tree_info & OPT_NOT_SHARED))
+ {
+ node *res2 = freeze_node(res);
+
+ if (res2 != res) {
+ return dmalloc_touch(node *, res2);
+ }
+ }
+ #endif /* SHARED_NODES */
+
#ifdef PIKE_DEBUG
if(d_flag > 3)
verify_shared_strings_tables();
1032:
node *res = mkemptynode();
res->token = F_CONSTANT;
res->node_info = OPT_NOT_SHARED;
+ res->tree_info = OPT_NOT_SHARED;
res->u.sval.type = T_INT;
res->u.sval.subtype = NUMBER_NUMBER;
res->u.sval.u.integer = nr;