~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff-delta.c

  • Committer: John Arbash Meinel
  • Date: 2010-08-23 18:59:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100823185922-ovs1s9huk95wngk8
Update What's New and NEWS

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, *old_entry;
 
691
    struct index_entry *entry, *entries;
692
692
 
693
693
    if (!src->buf || !src->size)
694
694
        return NULL;
789
789
    entry = entries;
790
790
    num_inserted = 0;
791
791
    for (; num_entries > 0; --num_entries, ++entry) {
 
792
        struct index_entry *next_bucket_entry, *cur_entry, *bucket_first_entry;
792
793
        hash_offset = (entry->val & old_index->hash_mask);
793
794
        /* The basic structure is a hash => packed_entries that fit in that
794
795
         * hash bucket. Things are structured such that the hash-pointers are
797
798
         * forward. If there are no NULL targets, then we know because
798
799
         * entry->ptr will not be NULL.
799
800
         */
800
 
        old_entry = old_index->hash[hash_offset + 1];
801
 
        old_entry--;
802
 
        while (old_entry->ptr == NULL
803
 
               && old_entry >= old_index->hash[hash_offset]) {
804
 
            old_entry--;
 
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--;
805
809
        }
806
 
        old_entry++;
807
 
        if (old_entry->ptr != NULL
808
 
            || old_entry >= old_index->hash[hash_offset + 1]) {
 
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) {
809
814
            /* There is no room for this entry, we have to resize */
810
815
            // char buff[128];
811
816
            // get_text(buff, entry->ptr);
822
827
            break;
823
828
        }
824
829
        num_inserted++;
825
 
        *old_entry = *entry;
 
830
        *cur_entry = *entry;
826
831
        /* For entries which we *do* manage to insert into old_index, we don't
827
832
         * want them double copied into the final output.
828
833
         */
848
853
    free(index);
849
854
}
850
855
 
851
 
unsigned long sizeof_delta_index(struct delta_index *index)
 
856
unsigned long
 
857
sizeof_delta_index(struct delta_index *index)
852
858
{
853
859
    if (index)
854
860
        return index->memsize;
867
873
             const void *trg_buf, unsigned long trg_size,
868
874
             unsigned long *delta_size, unsigned long max_size)
869
875
{
870
 
    unsigned int i, outpos, outsize, moff, msize, val;
 
876
    unsigned int i, outpos, outsize, moff, val;
 
877
    int msize;
871
878
    const struct source_info *msource;
872
879
    int inscnt;
873
880
    const unsigned char *ref_data, *ref_top, *data, *top;
938
945
                 entry++) {
939
946
                const unsigned char *ref;
940
947
                const unsigned char *src;
941
 
                unsigned int ref_size;
 
948
                int ref_size;
942
949
                if (entry->val != val)
943
950
                    continue;
944
951
                ref = entry->ptr;
951
958
                 * match more bytes with this location that we have already
952
959
                 * matched.
953
960
                 */
954
 
                if (ref_size > top - src)
 
961
                if (ref_size > (top - src))
955
962
                    ref_size = top - src;
956
963
                if (ref_size <= msize)
957
964
                    break;
958
965
                /* See how many bytes actually match at this location. */
959
966
                while (ref_size-- && *src++ == *ref)
960
967
                    ref++;
961
 
                if (msize < ref - entry->ptr) {
 
968
                if (msize < (ref - entry->ptr)) {
962
969
                    /* this is our best match so far */
963
970
                    msize = ref - entry->ptr;
964
971
                    msource = entry->src;