Changeset 184


Ignore:
Timestamp:
Jul 20, 2008, 6:39:35 AM (11 years ago)
Author:
cameron
Message:

Create stringpool.h

Location:
trunk/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/symtab.c

    r179 r184  
    11#include "symtab.h"
    22
    3 const int INIT_STRINGPOOL_SIZE = 4096;
    43
    54inline bool bit_test(unsigned char * bit_Map, int codepoint) {
     
    219218int Symbol_Table::Insert_Name(char * name, int lgth) {
    220219//      char * s = copy_name(name,lgth);
    221         char * s = pool->Insert(name,lgth);
     220        char * s = pool.Insert(name,lgth);
    222221        UTF8NameMap[s]=++(globalNameCount);
    223222        Name_Data name_data;
     
    302301        #endif
    303302//              char * s = copy_name(name,lgth);
    304                 char * s = pool->Insert(name,lgth);
     303                char * s = pool.Insert(name,lgth);
    305304                UTF8NameMap[s]=++(globalNameCount);
    306305                nameID = globalNameCount;
     
    366365        #endif
    367366//              char * s = copy_name(name,lgth);
    368                 char * s = pool->Insert(nmtoken,lgth);
     367                char * s = pool.Insert(nmtoken,lgth);
    369368                UTF8NmtokenMap[s]=++(globalNmtokenCount);
    370369                nmtokenID = globalNmtokenCount;
     
    456455//              UTF8NameTable.push_back(predefined[i]);
    457456        }*/
    458         pool = new StringPool;
    459 }
    460 
    461 
    462 StringPool::StringPool() {
    463        buffer_capacity = INIT_STRINGPOOL_SIZE;
    464        buffer_space_used = 0;
    465        pool_buffers.push_back(new char [buffer_capacity]);
    466 }
    467 
    468 StringPool::~StringPool() {
    469        vector<char * >::iterator i;
    470        for (i = pool_buffers.begin(); i != pool_buffers.end(); i++) {
    471                delete [] *i;
    472        }
    473 }
    474 
    475 char * StringPool::Insert(char * s, int lgth) {
    476        while (lgth + buffer_space_used >= buffer_capacity) {
    477                buffer_capacity *= 2;
    478                pool_buffers.push_back(new char [buffer_capacity]);
    479                buffer_space_used = 0;
    480        }
    481        char * insertion_ptr = &pool_buffers.back()[buffer_space_used];
    482        memcpy(insertion_ptr, s, lgth);
    483        insertion_ptr[lgth] = '\0';
    484        buffer_space_used += lgth + 1;
    485        return insertion_ptr;
    486 }
    487 
    488 
    489 
     457}
     458
     459
     460
     461
  • trunk/src/symtab.h

    r174 r184  
    1010
    1111#include "namechars.h"
     12#include "stringpool.h"
    1213
    1314struct eqstr
     
    2728char * predefined[] = {"lt", "gt", "amp", "quot", "apos"};
    2829
    29 /*  A StringPool object provides managed storage for strings.
    30    It can grow to accommodate as many strings as desired, subject
    31    to space availability.  It is implemented as a vector of
    32    pool buffers.  Initially a single buffer of size initial_capacity
    33    is allocated.  Strings are inserted into this area until insufficient
    34    space remains, at which point a new buffer is allocated for
    35    subsequent insertions.  */
    36 
    37 class StringPool {
    38 public:
    39        StringPool();
    40        ~StringPool();
    41        char * Insert(char * s, int lgth);
    42 private:
    43        int buffer_capacity;
    44        int buffer_space_used;
    45        vector<char *> pool_buffers;
    46 };
    4730
    4831class Symbol_Table {
     
    7962        char * reserved;
    8063        int reserved_lgth;
    81         StringPool * pool;
     64        StringPool<4096,100> pool;
    8265};
    8366
Note: See TracChangeset for help on using the changeset viewer.