@@ -165,7 +165,6 @@ ull DC_rbound(const DeltaChunk* dc)
165165}
166166
167167// Apply
168- // TODO: remove, just left it for reference
169168inline
170169void DC_apply (const DeltaChunk * dc , const uchar * base , PyObject * writer , PyObject * tmpargs )
171170{
@@ -252,7 +251,7 @@ ushort DC_count_encode_bytes(const DeltaChunk* dc)
252251// DELTA INFO
253252/////////////
254253typedef struct {
255- uint dso ; // delta stream offset
254+ uint dso ; // delta stream offset, relative to the very start of the stream
256255 uint to ; // target offset (cache)
257256} DeltaInfo ;
258257
@@ -281,10 +280,6 @@ int DIV_reserve_memory(DeltaInfoVector* vec, uint num_dc)
281280 return 1 ;
282281 }
283282
284- if (num_dc - vec -> reserved_size < 10 ){
285- num_dc += gDIV_grow_by ;
286- }
287-
288283#ifdef DEBUG
289284 bool was_null = vec -> mem == NULL ;
290285#endif
@@ -529,6 +524,8 @@ uint DIV_count_slice_bytes(const DeltaInfoVector* src, uint ofs, uint size)
529524 next_delta_info (src -> dstream + cdi -> dso , & dc );
530525
531526 if (dc .ts < size ) {
527+ // TODO: could just count size of the delta chunk in the stream instead
528+ // of reencoding
532529 num_bytes += DC_count_encode_bytes (& dc );
533530 size -= dc .ts ;
534531 } else {
@@ -731,7 +728,7 @@ PyObject* DCL_py_rbound(DeltaChunkList* self)
731728static
732729PyObject * DCL_apply (DeltaChunkList * self , PyObject * args )
733730{
734- /*
731+
735732 PyObject * pybuf = 0 ;
736733 PyObject * writeproc = 0 ;
737734 if (!PyArg_ParseTuple (args , "OO" , & pybuf , & writeproc )){
@@ -749,23 +746,24 @@ PyObject* DCL_apply(DeltaChunkList* self, PyObject* args)
749746 return NULL ;
750747 }
751748
752- const DeltaChunk* i = self->vec.mem;
753- const DeltaChunk* end = DIV_end(&self->vec);
754-
755- const uchar* data;
756- Py_ssize_t dlen;
757- PyObject_AsReadBuffer(pybuf, (const void**)&data, &dlen);
749+ const uchar * base ;
750+ Py_ssize_t baselen ;
751+ PyObject_AsReadBuffer (pybuf , (const void * * )& base , & baselen );
758752
759753 PyObject * tmpargs = PyTuple_New (1 );
760754
761- for(; i < end; i++){
762- DC_apply(i, data, writeproc, tmpargs);
755+ const uchar * data = TSI_first (& self -> istream );
756+ const uchar const * dend = TSI_end (& self -> istream );
757+
758+ DeltaChunk dc ;
759+ DC_init (& dc , 0 , 0 , 0 , NULL );
760+
761+ while (data < dend ){
762+ data = next_delta_info (data , & dc );
763+ DC_apply (& dc , base , writeproc , tmpargs );
763764 }
764765
765766 Py_DECREF (tmpargs );
766- */
767- // TODO
768- assert (0 );
769767 Py_RETURN_NONE ;
770768}
771769
@@ -911,7 +909,7 @@ static PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
911909 DeltaInfoVector div ;
912910 ToplevelStreamInfo tdsinfo ;
913911 TSI_init (& tdsinfo );
914- DIV_init (& div , 100 ); // should be enough to keep the average text file
912+ DIV_init (& div , 0 );
915913
916914
917915 // GET TOPLEVEL DELTA STREAM
@@ -1020,13 +1018,17 @@ static PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
10201018 error = 1 ;
10211019 }
10221020
1021+ #ifdef DEBUG
1022+ fprintf (stderr , "Before Connect: tdsinfo->num_chunks = %i, tdsinfo->bytelen = %i\n" , (int )tdsinfo .num_chunks , (int )tdsinfo .tdslen );
1023+ #endif
1024+
10231025 if (!DIV_connect_with_base (& tdsinfo , & div )){
10241026 error = 1 ;
10251027 }
10261028
10271029 #ifdef DEBUG
1028- fprintf (stderr , "tdsinfo->len = %i\n" , (int )tdsinfo .tdslen );
1029- fprintf (stderr , "div->size = %i, div->reserved_size = %i\n" , (int )div .size , (int )div .reserved_size );
1030+ fprintf (stderr , "after connect: tdsinfo->num_chunks = %i, tdsinfo->bytelen = %i \n" , ( int ) tdsinfo . num_chunks , (int )tdsinfo .tdslen );
1031+ fprintf (stderr , "div->num_chunks = %i, div->reserved_size = %i, div->bytelen=%i \n" , (int )div .size , (int )div .reserved_size , ( int ) dlen );
10301032 #endif
10311033
10321034 // destroy members, but keep memory
0 commit comments