--- parser3/src/main/pa_string.C 2003/01/22 15:39:08 1.172.2.1 +++ parser3/src/main/pa_string.C 2003/04/11 15:00:05 1.173 @@ -5,13 +5,13 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_STRING_C="$Date: 2003/01/22 15:39:08 $"; +static const char* IDENT_STRING_C="$Date: 2003/04/11 15:00:05 $"; #include "pcre.h" #include "pa_pool.h" #include "pa_string.h" -//#include "pa_hash.h" +#include "pa_hash.h" #include "pa_exception.h" #include "pa_common.h" #include "pa_array.h" @@ -26,7 +26,7 @@ static const char* IDENT_STRING_C="$Date #ifdef DEBUG_STRING_APPENDS_VS_EXPANDS ulong string_piece_appends=0; #endif -/* + String& String::OnPool(Pool& apool, const char *local_src, size_t src_size, bool tainted) { if(local_src && *local_src) { if(src_size==0) @@ -38,8 +38,8 @@ String& String::OnPool(Pool& apool, cons } else return *new(apool) String(apool); } -*/ -String::String(const char *src, size_t src_size, bool tainted) { +String::String(Pool& apool, const char *src, size_t src_size, bool tainted) : + Pooled(apool) { last_chunk=&head.chunk; head.chunk.count=CR_PREALLOCATED_COUNT; append_here=head.chunk.rows; @@ -51,17 +51,14 @@ String::String(const char *src, size_t s APPEND_CLEAN(src, src_size, 0, 0); } -String::String(const String& src) { +String::String(const String& src) : + Pooled(src.pool()) { last_chunk=&head.chunk; head.chunk.count=CR_PREALLOCATED_COUNT; append_here=head.chunk.rows; append(src, UL_PASS_APPENDED); } -void String::~String() { - // @todonow -} - size_t String::size() const { size_t result=0; @@ -84,12 +81,12 @@ void String::expand() { if(new_chunk_count>max_integral(Chunk::count_type)) new_chunk_count=max_integral(Chunk::count_type); - Chunk *new_chunk=static_cast(pa_malloc( + Chunk *new_chunk=static_cast(malloc( sizeof(Chunk)// count+interpadding(?)+rows[CR_PREALLOCATED_COUNT]+tailpadding(??) -sizeof(Chunk::rows_type) // PREALLOCATED rows +sizeof(Chunk::Row)*new_chunk_count // neaded rows +sizeof(Chunk *) // link size - )); + , 10)); new_chunk->rows[new_chunk->count=new_chunk_count].link=0; last_chunk->rows[last_chunk->count].link=new_chunk; @@ -335,7 +332,7 @@ const Origin& String::origin() const { #endif String& String::mid(size_t start, size_t finish) const { - String& result=*new String(); + String& result=*NEW String(pool()); start=min(start, size()); finish=max(start, finish); @@ -479,13 +476,13 @@ static void regex_options(const String * } /// @todo make replacement Table stacked -bool String::match(Charset& source_charset, - const String *aorigin, - const String& regexp, - const String *options, - Table **table, - Row_action row_action, void *info, - bool *was_global) const { +bool String::match( + const String *aorigin, + const String& regexp, + const String *options, + Table **table, + Row_action row_action, void *info, + bool *was_global) const { if(regexp.is_empty()) throw Exception(0, @@ -495,13 +492,13 @@ bool String::match(Charset& source_chars const char *pattern=regexp.cstr(); const char *errptr; int erroffset; - bool need_pre_post_match=false; + bool need_pre_post_match=false; int option_bits[2]; regex_options(options, option_bits, need_pre_post_match); if(was_global) *was_global=option_bits[1]!=0; pcre *code=pcre_compile(pattern, option_bits[0], &errptr, &erroffset, - source_charset.pcre_tables); + pool().get_source_charset().pcre_tables); if(!code) throw Exception(0, @@ -523,7 +520,8 @@ bool String::match(Charset& source_chars int ovector[ovecsize]; // create table - *table=new Table(*string_match_table_template); + Table::Action_options table_options; + *table=NEW Table(pool(), *string_match_table_template, table_options); int exec_option_bits=0; int prestart=0; @@ -550,7 +548,7 @@ bool String::match(Charset& source_chars int prefinish=ovector[0]; poststart=ovector[1]; - Array& row=*new Array(); + Array& row=*NEW Array(pool()); row+=need_pre_post_match?&mid(0, prefinish):0; // .prematch column value row+=need_pre_post_match?&mid(prefinish, poststart):0; // .match row+=need_pre_post_match?&mid(poststart, postfinish):0; // .postmatch @@ -576,9 +574,10 @@ bool String::match(Charset& source_chars } } -String& String::change_case(Charset& source_charset, Change_case_kind kind) const { - const unsigned char *tables=source_charset.pcre_tables; - String& result=*new String(); +String& String::change_case(Pool& pool, + Change_case_kind kind) const { + const unsigned char *tables=pool.get_source_charset().pcre_tables; + String& result=*new(pool) String(pool); const unsigned char *a; const unsigned char *b; @@ -601,7 +600,7 @@ String& String::change_case(Charset& sou } STRING_FOREACH_ROW( - char *new_cstr=(char *)pa_malloc(row->item.size); + char *new_cstr=(char *)pool.malloc(row->item.size, 12); char *dest=new_cstr; const char *src=row->item.ptr; for(int size=row->item.size; size--; src++) { @@ -621,11 +620,11 @@ String& String::change_case(Charset& sou } /// @test if in some piece were found no dict words, append it, not it's duplicate -String& String::replace(Dictionary& dict) const { +String& String::replace(Pool& pool, Dictionary& dict) const { char *lcstr=cstr(); const char *current=lcstr; - String& result=*new String(); + String& result=*new(pool) String(pool); STRING_FOREACH_ROW( IFNDEF_NO_STRING_ORIGIN( const char *joined_origin_file=row->item.origin.file; @@ -647,7 +646,7 @@ IFNDEF_NO_STRING_ORIGIN( // & one step back, see STRING_FOREACH_ROW --row; ++countdown; - char *new_cstr=(char *)pa_malloc((size_t)ceil(joined_size*dict.max_ratio())); + char *new_cstr=(char *)pool.malloc((size_t)ceil(joined_size*dict.max_ratio()), 14); char *dest=new_cstr; while(joined_size) { // there is a row where first column starts 'joined_ptr' @@ -672,11 +671,11 @@ IFNDEF_NO_STRING_ORIGIN( return result; } -String& String::join_chains(char** acstr) const { +String& String::join_chains(Pool& pool, char** acstr) const { char *lcstr=cstr(); const char *current=lcstr; - String& result=*new String(); + String& result=*new(pool) String(pool); STRING_FOREACH_ROW( IFNDEF_NO_STRING_ORIGIN( const char *joined_origin_file=row->item.origin.file; @@ -793,7 +792,7 @@ void String::serialize(size_t prolog_siz prolog_size +used_rows()*(sizeof(uchar)+sizeof(ushort)) +size(); - buf=pa_malloc(buf_size); + buf=malloc(buf_size,15); char *cur=(char *)buf+prolog_size; STRING_FOREACH_ROW(