Back to index

lightning-sunbird  0.9+nobinonly
Functions
jsd_atom.c File Reference
#include "jsd.h"

Go to the source code of this file.

Functions

 _atom_smasher (JSHashEntry *he, intN i, void *arg)
 _compareAtomKeys (const void *v1, const void *v2)
 _compareAtoms (const void *v1, const void *v2)
JSBool jsd_CreateAtomTable (JSDContext *jsdc)
void jsd_DestroyAtomTable (JSDContext *jsdc)
JSDAtomjsd_AddAtom (JSDContext *jsdc, const char *str)
JSDAtomjsd_CloneAtom (JSDContext *jsdc, JSDAtom *atom)
void jsd_DropAtom (JSDContext *jsdc, JSDAtom *atom)

Function Documentation

_atom_smasher ( JSHashEntry he,
intN  i,
void arg 
)

Definition at line 71 of file jsd_atom.c.

{
    JS_ASSERT(he);
    JS_ASSERT(he->value);
    JS_ASSERT(((JSDAtom*)(he->value))->str);

    free(((JSDAtom*)(he->value))->str);
    free(he->value);
    he->value = NULL;
    he->key   = NULL;
    return HT_ENUMERATE_NEXT;
}

Here is the caller graph for this function:

_compareAtomKeys ( const void v1,
const void v2 
)

Definition at line 85 of file jsd_atom.c.

{
    return 0 == strcmp((const char*)v1, (const char*)v2);
}        

Here is the caller graph for this function:

_compareAtoms ( const void v1,
const void v2 
)

Definition at line 91 of file jsd_atom.c.

{
    return 0 == strcmp(((JSDAtom*)v1)->str, ((JSDAtom*)v2)->str);
}        

Here is the caller graph for this function:

JSDAtom* jsd_AddAtom ( JSDContext jsdc,
const char *  str 
)

Definition at line 121 of file jsd_atom.c.

{
    JSDAtom* atom;

    if(!str)
    {
        JS_ASSERT(0);
        return NULL;
    }

    JSD_LOCK_ATOMS(jsdc);
    
    atom = (JSDAtom*) JS_HashTableLookup(jsdc->atoms, str);

    if( atom )
        atom->refcount++;
    else
    {
        atom = (JSDAtom*) malloc(sizeof(JSDAtom));
        if( atom )
        {
            atom->str = strdup(str);
            atom->refcount = 1;
            if(!JS_HashTableAdd(jsdc->atoms, atom->str, atom))
            {
                free(atom->str);
                free(atom);
                atom = NULL;
            }
        }
    }

    JSD_UNLOCK_ATOMS(jsdc);
    return atom;
}        

Here is the call graph for this function:

Here is the caller graph for this function:

JSDAtom* jsd_CloneAtom ( JSDContext jsdc,
JSDAtom atom 
)

Definition at line 158 of file jsd_atom.c.

{
    JSD_LOCK_ATOMS(jsdc);
    atom->refcount++;
    JSD_UNLOCK_ATOMS(jsdc);
    return atom;
}        

Definition at line 98 of file jsd_atom.c.

{
    jsdc->atoms = JS_NewHashTable(256, JS_HashString,
                                  _compareAtomKeys, _compareAtoms,
                                  NULL, NULL);
#ifdef TEST_ATOMS
    _testAtoms(jsdc);
#endif    
    return (JSBool) jsdc->atoms;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 110 of file jsd_atom.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void jsd_DropAtom ( JSDContext jsdc,
JSDAtom atom 
)

Definition at line 167 of file jsd_atom.c.

{
    JSD_LOCK_ATOMS(jsdc);
    if(! --atom->refcount)
    {
        JS_HashTableRemove(jsdc->atoms, atom->str);
        free(atom->str);
        free(atom);
    }
    JSD_UNLOCK_ATOMS(jsdc);
}        

Here is the call graph for this function:

Here is the caller graph for this function: