@@ -88,42 +88,41 @@ static int64_t matchlen(u_char *old, int64_t oldsize, u_char *new,
88
88
return i ;
89
89
}
90
90
91
- int64_t max_len = 0 ;
92
-
93
91
/**
94
92
* Finds the longest matching array of bytes between the OLD and NEW file. The
95
93
* old file is suffix-sorted; the suffix-sorted array is stored at I, and
96
- * indices to search between are indicated by ST (start) and EN (end). Returns
97
- * the length of the match, and POS is updated to the position of the match
98
- * within OLD.
94
+ * indices to search between are indicated by ST (start) and EN (end). The
95
+ * function does not return a value, but once a match is determined, POS is
96
+ * updated to the position of the match within OLD, and MAX_LEN is set to the
97
+ * match length.
99
98
*/
100
- static int64_t search (int64_t * I , u_char * old , int64_t oldsize ,
101
- u_char * new , int64_t newsize , int64_t st , int64_t en ,
102
- int64_t * pos )
99
+ static void search (int64_t * I , u_char * old , int64_t oldsize ,
100
+ u_char * new , int64_t newsize , int64_t st , int64_t en ,
101
+ int64_t * pos , int64_t * max_len )
103
102
{
104
103
int64_t x , y ;
105
104
106
105
/* Initialize max_len for the binary search */
107
106
if (st == 0 && en == oldsize ) {
108
- max_len = matchlen (old , oldsize , new , newsize );
107
+ * max_len = matchlen (old , oldsize , new , newsize );
109
108
* pos = I [st ];
110
109
}
111
110
112
111
/* The binary search terminates here when "en" and "st" are adjacent
113
112
* indices in the suffix-sorted array. */
114
113
if (en - st < 2 ) {
115
114
x = matchlen (old + I [st ], oldsize - I [st ], new , newsize );
116
- if (x > max_len ) {
117
- max_len = x ;
115
+ if (x > * max_len ) {
116
+ * max_len = x ;
118
117
* pos = I [st ];
119
118
}
120
119
y = matchlen (old + I [en ], oldsize - I [en ], new , newsize );
121
- if (y > max_len ) {
122
- max_len = y ;
120
+ if (y > * max_len ) {
121
+ * max_len = y ;
123
122
* pos = I [en ];
124
123
}
125
124
126
- return max_len ;
125
+ return ;
127
126
}
128
127
129
128
x = st + (en - st ) / 2 ;
@@ -133,16 +132,16 @@ static int64_t search(int64_t *I, u_char *old, int64_t oldsize,
133
132
134
133
/* This match *could* be the longest one, so check for that here */
135
134
int64_t tmp = matchlen (oldoffset , length , new , length );
136
- if (tmp > max_len ) {
137
- max_len = tmp ;
135
+ if (tmp > * max_len ) {
136
+ * max_len = tmp ;
138
137
* pos = I [x ];
139
138
}
140
139
141
140
/* Determine how to continue the binary search */
142
141
if (memcmp (oldoffset , new , length ) < 0 ) {
143
- return search (I , old , oldsize , new , newsize , x , en , pos );
142
+ return search (I , old , oldsize , new , newsize , x , en , pos , max_len );
144
143
} else {
145
- return search (I , old , oldsize , new , newsize , st , x , pos );
144
+ return search (I , old , oldsize , new , newsize , st , x , pos , max_len );
146
145
}
147
146
}
148
147
@@ -617,9 +616,8 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
617
616
oldscore = 0 ;
618
617
619
618
for (scsc = scan += len ; scan < newsize ; scan ++ ) {
620
- len =
621
- search (I , old_data , oldsize , new_data + scan , newsize - scan ,
622
- 0 , oldsize , & pos );
619
+ search (I , old_data , oldsize , new_data + scan , newsize - scan ,
620
+ 0 , oldsize , & pos , & len );
623
621
624
622
for (; scsc < scan + len ; scsc ++ ) {
625
623
if ((scsc + lastoffset < oldsize ) &&
0 commit comments