~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-06-16 13:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090616135714-8o7jdtqqsfuv914z
The new code removes a get_parent_map call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
688
688
    const unsigned char *data, *buffer, *top;
689
689
    unsigned char cmd;
690
690
    struct delta_index *new_index;
691
 
    struct index_entry *entry, *entries;
 
691
    struct index_entry *entry, *entries, *old_entry;
692
692
 
693
693
    if (!src->buf || !src->size)
694
694
        return NULL;
713
713
    prev_val = ~0;
714
714
    data = buffer;
715
715
    /* target size */
716
 
    /* get_delta_hdr_size doesn't mutate the content, just moves the
717
 
     * start-of-data pointer, so it is safe to do the cast.
718
 
     */
719
 
    get_delta_hdr_size((unsigned char**)&data, top);
 
716
    get_delta_hdr_size(&data, top);
720
717
    entry = entries; /* start at the first slot */
721
718
    num_entries = 0; /* calculate the real number of entries */
722
719
    while (data < top) {
789
786
    entry = entries;
790
787
    num_inserted = 0;
791
788
    for (; num_entries > 0; --num_entries, ++entry) {
792
 
        struct index_entry *next_bucket_entry, *cur_entry, *bucket_first_entry;
793
789
        hash_offset = (entry->val & old_index->hash_mask);
794
790
        /* The basic structure is a hash => packed_entries that fit in that
795
791
         * hash bucket. Things are structured such that the hash-pointers are
798
794
         * forward. If there are no NULL targets, then we know because
799
795
         * entry->ptr will not be NULL.
800
796
         */
801
 
        // The start of the next bucket, this may point past the end of the
802
 
        // entry table if hash_offset is the last bucket.
803
 
        next_bucket_entry = old_index->hash[hash_offset + 1];
804
 
        // First entry in this bucket
805
 
        bucket_first_entry = old_index->hash[hash_offset];
806
 
        cur_entry = next_bucket_entry - 1;
807
 
        while (cur_entry->ptr == NULL && cur_entry >= bucket_first_entry) {
808
 
            cur_entry--;
 
797
        old_entry = old_index->hash[hash_offset + 1];
 
798
        old_entry--;
 
799
        while (old_entry->ptr == NULL
 
800
               && old_entry >= old_index->hash[hash_offset]) {
 
801
            old_entry--;
809
802
        }
810
 
        // cur_entry now either points at the first NULL, or it points to
811
 
        // next_bucket_entry if there were no blank spots.
812
 
        cur_entry++;
813
 
        if (cur_entry >= next_bucket_entry || cur_entry->ptr != NULL) {
 
803
        old_entry++;
 
804
        if (old_entry->ptr != NULL
 
805
            || old_entry >= old_index->hash[hash_offset + 1]) {
814
806
            /* There is no room for this entry, we have to resize */
815
807
            // char buff[128];
816
808
            // get_text(buff, entry->ptr);
827
819
            break;
828
820
        }
829
821
        num_inserted++;
830
 
        *cur_entry = *entry;
 
822
        *old_entry = *entry;
831
823
        /* For entries which we *do* manage to insert into old_index, we don't
832
824
         * want them double copied into the final output.
833
825
         */
853
845
    free(index);
854
846
}
855
847
 
856
 
unsigned long
857
 
sizeof_delta_index(struct delta_index *index)
 
848
unsigned long sizeof_delta_index(struct delta_index *index)
858
849
{
859
850
    if (index)
860
851
        return index->memsize;
873
864
             const void *trg_buf, unsigned long trg_size,
874
865
             unsigned long *delta_size, unsigned long max_size)
875
866
{
876
 
    unsigned int i, outpos, outsize, moff, val;
877
 
    int msize;
 
867
    unsigned int i, outpos, outsize, moff, msize, val;
878
868
    const struct source_info *msource;
879
869
    int inscnt;
880
870
    const unsigned char *ref_data, *ref_top, *data, *top;
945
935
                 entry++) {
946
936
                const unsigned char *ref;
947
937
                const unsigned char *src;
948
 
                int ref_size;
 
938
                unsigned int ref_size;
949
939
                if (entry->val != val)
950
940
                    continue;
951
941
                ref = entry->ptr;
958
948
                 * match more bytes with this location that we have already
959
949
                 * matched.
960
950
                 */
961
 
                if (ref_size > (top - src))
 
951
                if (ref_size > top - src)
962
952
                    ref_size = top - src;
963
953
                if (ref_size <= msize)
964
954
                    break;
965
955
                /* See how many bytes actually match at this location. */
966
956
                while (ref_size-- && *src++ == *ref)
967
957
                    ref++;
968
 
                if (msize < (ref - entry->ptr)) {
 
958
                if (msize < ref - entry->ptr) {
969
959
                    /* this is our best match so far */
970
960
                    msize = ref - entry->ptr;
971
961
                    msource = entry->src;