/[classpath]/classpath/native/jni/classpath/native_state.c
ViewVC logotype

Diff of /classpath/native/jni/classpath/native_state.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by mark, Tue Jan 22 22:27:02 2002 UTC revision 1.3 by tromey, Sun Nov 10 07:59:05 2002 UTC
# Line 1  Line 1 
1  /* Magical NSA API -- Associate a C ptr with an instance of an object  /* Magical NSA API -- Associate a C ptr with an instance of an object
2     Copyright (C) 1998 Free Software Foundation, Inc.     Copyright (C) 1998, 2002 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 72  init_state_table (JNIEnv *env, jclass cl Line 72  init_state_table (JNIEnv *env, jclass cl
72    return init_state_table_with_size (env, clazz, DEFAULT_TABLE_SIZE);    return init_state_table_with_size (env, clazz, DEFAULT_TABLE_SIZE);
73  }  }
74    
75  static  static void *
 void *  
76  remove_node (struct state_node **head, jint obj_id)  remove_node (struct state_node **head, jint obj_id)
77  {  {
78    struct state_node *back_ptr = NULL;    struct state_node *back_ptr = NULL;
# Line 99  remove_node (struct state_node **head, j Line 98  remove_node (struct state_node **head, j
98    return NULL;    return NULL;
99  }  }
100                            
101  static  static void *
 void *  
102  get_node (struct state_node **head, jint obj_id)  get_node (struct state_node **head, jint obj_id)
103  {  {
104    struct state_node *back_ptr = NULL;    struct state_node *back_ptr = NULL;
# Line 129  get_node (struct state_node **head, jint Line 127  get_node (struct state_node **head, jint
127    return NULL;    return NULL;
128  }  }
129    
130  static  static void
 void  
131  add_node (struct state_node **head, jint obj_id, void *state)  add_node (struct state_node **head, jint obj_id, void *state)
132  {  {
133    struct state_node *node = *head;    struct state_node *node = *head;
134    struct state_node *back_ptr = *head;    struct state_node *back_ptr = *head;
135    
136    struct state_node *new_node;    struct state_node *new_node = NULL;
   new_node = (struct state_node *) malloc (sizeof (struct state_node));  
   new_node->key = obj_id;  
   new_node->c_state = state;  
137    
138    /* insert into an empty slot */    if (node != NULL)
   if (node == NULL)  
139      {      {
140        new_node->next = NULL;        while (node->next != NULL && obj_id != node->key)
141        *head = new_node;          {
142        return;            back_ptr = node;
143              node = node->next;
144            }
145    
146          /* If we're updating a node, setup to move it to the front of
147             the list.  */
148          if (node->key == obj_id)
149            {
150              back_ptr->next = node->next;
151              new_node = node;
152            }
153      }      }
154    
155    /* collision resolution */    if (new_node == NULL)
   /* try to find the old node, if it exists */  
   while (node->next != NULL && obj_id != node->key)  
156      {      {
157        back_ptr = node;        new_node = (struct state_node *) malloc (sizeof (struct state_node));
158        node = node->next;        new_node->key = obj_id;
159          new_node->c_state = state;
160      }      }
161    
162    /* if we're updating a node, setup to move it to the front of the list */    /* Insert node at the beginning.  */
   if (node->key == obj_id)  
     back_ptr->next = node->next;  
     
   /* move node to the beginning */  
163    new_node->next = *head;    new_node->next = *head;
164    *head = new_node;    *head = new_node;
165  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26