--- parser3/src/main/pa_string.C 2001/11/21 08:26:55 1.124 +++ parser3/src/main/pa_string.C 2001/11/23 10:41:21 1.125.2.1 @@ -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.125.2.1 2001/11/23 10:41:21 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, 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); + memcpy(cur, &row->item.size, sizeof(ushort)); + cur+=sizeof(ushort); // bytes memcpy(cur, row->item.ptr, row->item.size); cur+=row->item.size; @@ -875,31 +879,18 @@ 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=*(const uchar*)((const char*)cur+0); + ushort size=*(const ushort*)((const char*)cur+sizeof(uchar)); + const char *ptr=(const char*)cur+sizeof(uchar)+sizeof(ushort); + APPEND(ptr, size, lang, file, 0); - size_t piece_size=sizeof(p.lang)+sizeof(p.size)+p.size; + size_t piece_size=sizeof(uchar)+sizeof(ushort)+size; cur+=piece_size; buf_size-=piece_size; } } -