--- parser3/src/main/pa_string.C 2001/11/21 08:26:55 1.124 +++ parser3/src/main/pa_string.C 2001/12/10 09:44:17 1.129 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_string.C,v 1.124 2001/11/21 08:26:55 paf Exp $ + $Id: pa_string.C,v 1.129 2001/12/10 09:44:17 paf Exp $ */ #include "pa_config_includes.h" @@ -189,7 +189,8 @@ break2: int String::cmp(int& partial, const String& src, size_t this_offset, Untaint_lang lang) const { partial=-1; - this_offset=min(this_offset, size()-1); + size_t a_size=size(); + this_offset=min(this_offset, a_size-1); const Chunk *a_chunk=&head; const Chunk *b_chunk=&src.head; @@ -204,7 +205,7 @@ int String::cmp(int& partial, const Stri int result; size_t pos=0; - bool a_break=size()==0; + bool a_break=a_size==0; bool b_break=src.size()==0; if(!(a_break || b_break)) while(true) { if(pos+a_row->item.size > this_offset) { @@ -277,8 +278,9 @@ int String::cmp(int& partial, const Stri int String::cmp(int& partial, const char* b_ptr, size_t src_size, size_t this_offset, Untaint_lang lang) const { partial=-1; + size_t a_size=size(); size_t b_size=src_size?src_size:b_ptr?strlen(b_ptr):0; - this_offset=min(this_offset, size()-1); + this_offset=min(this_offset, a_size-1); const Chunk *a_chunk=&head; const Chunk::Row *a_row=a_chunk->rows; @@ -288,7 +290,7 @@ int String::cmp(int& partial, const char uint a_countdown=a_chunk->count; size_t pos=0; - bool a_break=size()==0; + bool a_break=a_size==0; bool b_break=b_size==0; if(!(a_break || b_break)) while(true) { if(pos+a_row->item.size > this_offset) { @@ -395,7 +397,8 @@ break2: int String::pos(const String& substr, int result, Untaint_lang lang) const { - for(; resultitem.lang==joined_lang) joined_size+=row->item.size; else - break; + goto break21; } if(chunk=row->link) { start_i=0; @@ -710,7 +714,7 @@ break21:; memcpy(ptr, row->item.ptr, row->item.size); ptr+=row->item.size; } else - break; + goto break22; } if(chunk=row->link) { start_i=0; @@ -848,6 +852,13 @@ int String::as_int() const { return result; } +inline void ushort2uchars(ushort word, uchar& byte1, uchar& byte2) { + byte1=word&0xFF; + byte2=word>>8; +} +inline ushort uchars2ushort(uchar byte1, uchar byte2) { + return (byte2<<8) | byte1; +} /* @todo maybe network order worth spending some effort? don't bothering myself with network byte order, am not planning to be able to move resulting file across platforms @@ -856,18 +867,20 @@ int String::as_int() const { void String::serialize(size_t prolog_size, void *& buf, size_t& buf_size) const { buf_size= prolog_size - +used_rows()*(sizeof(Untaint_lang)+sizeof(size_t)) + +used_rows()*(sizeof(uchar)+sizeof(ushort)) +size(); buf=malloc(buf_size,15); char *cur=(char *)buf+prolog_size; STRING_FOREACH_ROW( // lang - memcpy(cur, &row->item.lang, sizeof(Untaint_lang)); - cur+=sizeof(Untaint_lang); + memcpy(cur, &row->item.lang, sizeof(uchar)); + cur+=sizeof(uchar); // size - memcpy(cur, &row->item.size, sizeof(size_t)); - cur+=sizeof(size_t); + uchar byte1; uchar byte2; + ushort2uchars(row->item.size, byte1, byte2); + memcpy(cur, &byte1, sizeof(uchar)); cur+=sizeof(uchar); + memcpy(cur, &byte2, sizeof(uchar)); cur+=sizeof(uchar); // bytes memcpy(cur, row->item.ptr, row->item.size); cur+=row->item.size; @@ -875,31 +888,23 @@ void String::serialize(size_t prolog_siz break2: ; } - -/* @todo maybe network order worth spending some effort? - don't bothering myself with network byte order, - am not planning to be able to move resulting file across platforms - for now -*/ -#ifndef DOXYGEN -struct Serialized_piece { - String::Untaint_lang lang; - size_t size; - char ptr[1]; -}; -#endif - void String::deserialize(size_t prolog_size, void *buf, size_t buf_size, const char *file) { - char *cur=((char *)buf)+prolog_size; + char *cur=(char *)buf+prolog_size; buf_size-=prolog_size; while(buf_size) { - Serialized_piece& p=*(Serialized_piece *)cur; - APPEND(p.ptr, p.size, p.lang, file, 0); + uchar lang=*(uchar *)(cur); + + ushort size=uchars2ushort( + *(uchar*)(cur+sizeof(uchar)*1), + *(uchar*)(cur+sizeof(uchar)*2) + ); - size_t piece_size=sizeof(p.lang)+sizeof(p.size)+p.size; + const char *ptr=(const char*)(cur+sizeof(uchar)*3); + APPEND(ptr, size, lang, file, 0); + + size_t piece_size=sizeof(uchar)+sizeof(ushort)+size; cur+=piece_size; buf_size-=piece_size; } } -