~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff-delta.c

  • Committer: John Arbash Meinel
  • Date: 2009-03-19 06:15:49 UTC
  • mto: (3735.2.157 brisbane-core)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090319061549-fzk7na4uczpev2iy
Simplify the code a bit. We don't repack as often, so go with a
more obvious code, rather than trying tricks with memcpy()
(it didn't seem to really help, anyway).

Show diffs side-by-side

added added

removed removed

Lines of Context:
212
212
pack_delta_index(struct unpacked_index_entry **hash, unsigned int hsize,
213
213
                 unsigned int num_entries, struct delta_index *old_index)
214
214
{
215
 
    unsigned int i, j, hmask, memsize, to_copy, fit_in_old, copied_count;
 
215
    unsigned int i, j, hmask, memsize, fit_in_old, copied_count;
216
216
    struct unpacked_index_entry *entry;
217
217
    struct delta_index *index;
218
218
    struct index_entry *packed_entry, **packed_hash, *old_entry, *copy_from;
275
275
        if (fit_in_old) {
276
276
            fprintf(stderr, "Fit all %d entries into old index\n",
277
277
                            copied_count);
 
278
            /* No need to allocate a new buffer */
278
279
            return NULL;
279
280
        } else {
280
281
            fprintf(stderr, "Fit only %d entries into old index,"
322
323
             */
323
324
            j = i & old_index->hash_mask;
324
325
            copy_from = old_index->hash[j];
325
 
            to_copy = 0;
326
326
            for (old_entry = old_index->hash[j];
327
327
                 old_entry < old_index->hash[j + 1] && old_entry->ptr != NULL;
328
328
                 old_entry++) {
329
329
                if ((old_entry->val & hmask) == i) {
330
 
                    to_copy += 1;
331
 
                } else {
332
 
                    /* We reached the end of a string of entries that should
333
 
                     * be copied. Copy the group, and then move the pointers.
334
 
                     */
335
 
                    if (to_copy > 0) {
336
 
                        memcpy(packed_entry, copy_from,
337
 
                               sizeof(*old_entry)*to_copy);
338
 
                        packed_entry += to_copy;
339
 
                        to_copy = 0;
340
 
                    }
341
 
                    /* Don't copy *this* entry, and start the copy after this */
342
 
                    copy_from = old_entry + 1;
 
330
                    *packed_entry++ = *old_entry;
343
331
                }
344
332
            }
345
 
            if (to_copy > 0) {
346
 
                memcpy(packed_entry, copy_from,
347
 
                       sizeof(*old_entry)*to_copy);
348
 
                packed_entry += to_copy;
349
 
                to_copy = 0;
350
 
            }
351
333
        }
352
334
        for (entry = hash[i]; entry; entry = entry->next) {
353
335
            *packed_entry++ = entry->entry;
354
336
        }
 
337
        /* TODO: At this point packed_entry - packed_hash[i] is the number of
 
338
         *       records that we have inserted into this hash bucket.
 
339
         *       We should *really* consider doing some limiting along the
 
340
         *       lines of limit_hash_buckets() to avoid pathological behavior.
 
341
         */
355
342
        /* Now add extra 'NULL' entries that we can use for future expansion. */
356
343
        for (j = 0; j < EXTRA_NULLS; ++j ) {
357
344
            *packed_entry++ = null_entry;