| 27 | | OIndex orInternAtom( const char* str, int len ) |
| | 27 | typedef struct |
| | 28 | { |
| | 29 | uint16_t nameIndex; // Index into BIN_ATOM_NAMES ptr.c |
| | 30 | uint16_t nameLen; |
| | 31 | } |
| | 32 | AtomRec; |
| | 33 | |
| | 34 | |
| | 35 | /** |
| | 36 | Appends atom name to string. |
| | 37 | */ |
| | 38 | void orAtomStr( OAtom atom, OString* str ) |
| | 39 | { |
| | 40 | OBinary* names; |
| | 41 | AtomRec* rec; |
| | 42 | |
| | 43 | rec = ((AtomRec*) orEnv->atoms.buf) + atom; |
| | 44 | names = orStringPtr( BIN_ATOM_NAMES ); |
| | 45 | |
| | 46 | orArrayReserve( str, sizeof(char), str->used + rec->nameLen ); |
| | 47 | memCpy( str->charArray + str->used, |
| | 48 | names->charArray + rec->nameIndex, |
| | 49 | rec->nameLen ); |
| | 50 | str->used += rec->nameLen; |
| | 51 | } |
| | 52 | |
| | 53 | |
| | 54 | const char* orAtomCString( OAtom atom ) |
| | 55 | { |
| | 56 | static char buf[ MAX_WORD_LEN + 1 ]; |
| | 57 | OBinary* names; |
| | 58 | AtomRec* rec; |
| | 59 | |
| | 60 | rec = ((AtomRec*) orEnv->atoms.buf) + atom; |
| | 61 | names = orStringPtr( BIN_ATOM_NAMES ); |
| | 62 | |
| | 63 | memCpy( buf, names->charArray + rec->nameIndex, rec->nameLen ); |
| | 64 | buf[ rec->nameLen ] = '\0'; |
| | 65 | return buf; |
| | 66 | } |
| | 67 | |
| | 68 | |
| | 69 | /** |
| | 70 | Add atom to environment. |
| | 71 | |
| | 72 | \param str Name of atom. |
| | 73 | \param len Number of characters. Str will be truncated if greater than 32. |
| | 74 | |
| | 75 | \returns Atom |
| | 76 | */ |
| | 77 | OAtom orInternAtom( const char* str, int len ) |
| 83 | | // Must increment atoms->used after orMakeCString() in case garbage |
| 84 | | // collection occurs (*it will be uninitialized). |
| 85 | | //OA_EXPAND1( OIndex, atoms, it ); |
| 86 | | orArrayReserve(atoms, sizeof(OIndex), atoms->used+1); |
| 87 | | it = atoms->indices + atoms->used; |
| 88 | | *it = orMakeCString( orTmp, len ); |
| 89 | | ++atoms->used; |
| 90 | | return it - atoms->indices; |
| | 136 | OA_EXPAND1( AtomRec, atoms, rec ); |
| | 137 | rec->nameIndex = names->used; |
| | 138 | rec->nameLen = len; |
| | 139 | |
| | 140 | orArrayReserve( names, sizeof(char), names->used + len ); |
| | 141 | memCpy( names->charArray + names->used, buf, len ); |
| | 142 | names->used += len; |
| | 143 | |
| | 144 | done: |
| | 145 | |
| | 146 | return rec - ((AtomRec*) atoms->buf); |