comparison kdiff3/src/gnudiff_io.cpp @ 66:efe33e938730

0.9.86
author joachim99
date Thu, 16 Sep 2004 02:40:08 +0000
parents 32d5cbf9db71
children d7cafcda8c99
comparison
equal deleted inserted replaced
65:8ea11c8efeb5 66:efe33e938730
267 { 267 {
268 /* Create a new equivalence class in this bucket. */ 268 /* Create a new equivalence class in this bucket. */
269 i = eqs_index++; 269 i = eqs_index++;
270 if (i == eqs_alloc) 270 if (i == eqs_alloc)
271 { 271 {
272 if ((int)(PTRDIFF_MAX / (2 * sizeof *eqs)) <= eqs_alloc) 272 if ((lin)(PTRDIFF_MAX / (2 * sizeof *eqs)) <= eqs_alloc)
273 xalloc_die (); 273 xalloc_die ();
274 eqs_alloc *= 2; 274 eqs_alloc *= 2;
275 eqs = (equivclass*)xrealloc (eqs, eqs_alloc * sizeof *eqs); 275 eqs = (equivclass*)xrealloc (eqs, eqs_alloc * sizeof *eqs);
276 } 276 }
277 eqs[i].next = *bucket; 277 eqs[i].next = *bucket;
306 306
307 /* Maybe increase the size of the line table. */ 307 /* Maybe increase the size of the line table. */
308 if (line == alloc_lines) 308 if (line == alloc_lines)
309 { 309 {
310 /* Double (alloc_lines - linbuf_base) by adding to alloc_lines. */ 310 /* Double (alloc_lines - linbuf_base) by adding to alloc_lines. */
311 if ((int)(PTRDIFF_MAX / 3) <= alloc_lines 311 if ((lin)(PTRDIFF_MAX / 3) <= alloc_lines
312 || (int)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base 312 || (lin)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base
313 || (int)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base) 313 || (lin)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base)
314 xalloc_die (); 314 xalloc_die ();
315 alloc_lines = 2 * alloc_lines - linbuf_base; 315 alloc_lines = 2 * alloc_lines - linbuf_base;
316 cureqs =(lin*) xrealloc (cureqs, alloc_lines * sizeof *cureqs); 316 cureqs =(lin*) xrealloc (cureqs, alloc_lines * sizeof *cureqs);
317 linbuf += linbuf_base; 317 linbuf += linbuf_base;
318 linbuf = (const char**) xrealloc (linbuf, 318 linbuf = (const char**) xrealloc (linbuf,
332 Record one more line start than lines, 332 Record one more line start than lines,
333 so that we can compute the length of any buffered line. */ 333 so that we can compute the length of any buffered line. */
334 if (line == alloc_lines) 334 if (line == alloc_lines)
335 { 335 {
336 /* Double (alloc_lines - linbuf_base) by adding to alloc_lines. */ 336 /* Double (alloc_lines - linbuf_base) by adding to alloc_lines. */
337 if ((int)(PTRDIFF_MAX / 3) <= alloc_lines 337 if ((lin)(PTRDIFF_MAX / 3) <= alloc_lines
338 || (int)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base 338 || (lin)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base
339 || (int)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base) 339 || (lin)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base)
340 xalloc_die (); 340 xalloc_die ();
341 alloc_lines = 2 * alloc_lines - linbuf_base; 341 alloc_lines = 2 * alloc_lines - linbuf_base;
342 linbuf += linbuf_base; 342 linbuf += linbuf_base;
343 linbuf = (const char**)xrealloc (linbuf, 343 linbuf = (const char**)xrealloc (linbuf,
344 (alloc_lines - linbuf_base) * sizeof *linbuf); 344 (alloc_lines - linbuf_base) * sizeof *linbuf);
415 static lin 415 static lin
416 guess_lines (lin n, size_t s, size_t t) 416 guess_lines (lin n, size_t s, size_t t)
417 { 417 {
418 size_t guessed_bytes_per_line = n < 10 ? 32 : s / (n - 1); 418 size_t guessed_bytes_per_line = n < 10 ? 32 : s / (n - 1);
419 lin guessed_lines = MAX (1, t / guessed_bytes_per_line); 419 lin guessed_lines = MAX (1, t / guessed_bytes_per_line);
420 return MIN (guessed_lines, (int)(PTRDIFF_MAX / (2 * sizeof (char *) + 1) - 5)) + 5; 420 return MIN (guessed_lines, (lin)(PTRDIFF_MAX / (2 * sizeof (char *) + 1) - 5)) + 5;
421 } 421 }
422 422
423 /* Given a vector of two file_data objects, find the identical 423 /* Given a vector of two file_data objects, find the identical
424 prefixes and suffixes of each object. */ 424 prefixes and suffixes of each object. */
425 425
548 of the line buffer; they'll be moved to the proper location later. 548 of the line buffer; they'll be moved to the proper location later.
549 Handle 1 more line than the context says (because we count 1 too many), 549 Handle 1 more line than the context says (because we count 1 too many),
550 rounded up to the next power of 2 to speed index computation. */ 550 rounded up to the next power of 2 to speed index computation. */
551 551
552 if (no_diff_means_no_output 552 if (no_diff_means_no_output
553 && context < int(LIN_MAX / 4) && context < int(n0)) 553 && context < (lin)(LIN_MAX / 4) && context < (lin)(n0))
554 { 554 {
555 middle_guess = guess_lines (0, 0, p0 - filevec[0].prefix_end); 555 middle_guess = guess_lines (0, 0, p0 - filevec[0].prefix_end);
556 suffix_guess = guess_lines (0, 0, buffer0 + n0 - p0); 556 suffix_guess = guess_lines (0, 0, buffer0 + n0 - p0);
557 for (prefix_count = 1; prefix_count <= context; prefix_count *= 2) 557 for (prefix_count = 1; prefix_count <= context; prefix_count *= 2)
558 continue; 558 continue;
579 while (p0 != end0) 579 while (p0 != end0)
580 { 580 {
581 lin l = lines++ & prefix_mask; 581 lin l = lines++ & prefix_mask;
582 if (l == alloc_lines0) 582 if (l == alloc_lines0)
583 { 583 {
584 if (int(PTRDIFF_MAX / (2 * sizeof *linbuf0)) <= alloc_lines0) 584 if ((lin)(PTRDIFF_MAX / (2 * sizeof *linbuf0)) <= alloc_lines0)
585 xalloc_die (); 585 xalloc_die ();
586 alloc_lines0 *= 2; 586 alloc_lines0 *= 2;
587 linbuf0 = (const char**) xrealloc (linbuf0, alloc_lines0 * sizeof *linbuf0); 587 linbuf0 = (const char**) xrealloc (linbuf0, alloc_lines0 * sizeof *linbuf0);
588 } 588 }
589 linbuf0[l] = p0; 589 linbuf0[l] = p0;
597 597
598 middle_guess = guess_lines (lines, p0 - buffer0, p1 - filevec[1].prefix_end); 598 middle_guess = guess_lines (lines, p0 - buffer0, p1 - filevec[1].prefix_end);
599 suffix_guess = guess_lines (lines, p0 - buffer0, buffer1 + n1 - p1); 599 suffix_guess = guess_lines (lines, p0 - buffer0, buffer1 + n1 - p1);
600 alloc_lines1 = buffered_prefix + middle_guess + MIN (context, suffix_guess); 600 alloc_lines1 = buffered_prefix + middle_guess + MIN (context, suffix_guess);
601 if (alloc_lines1 < buffered_prefix 601 if (alloc_lines1 < buffered_prefix
602 || int(PTRDIFF_MAX / sizeof *linbuf1) <= alloc_lines1) 602 || (lin)(PTRDIFF_MAX / sizeof *linbuf1) <= alloc_lines1)
603 xalloc_die (); 603 xalloc_die ();
604 linbuf1 = (const char**)xmalloc (alloc_lines1 * sizeof *linbuf1); 604 linbuf1 = (const char**)xmalloc (alloc_lines1 * sizeof *linbuf1);
605 605
606 if (buffered_prefix != lines) 606 if (buffered_prefix != lines)
607 { 607 {
654 int i; 654 int i;
655 655
656 find_identical_ends (filevec); 656 find_identical_ends (filevec);
657 657
658 equivs_alloc = filevec[0].alloc_lines + filevec[1].alloc_lines + 1; 658 equivs_alloc = filevec[0].alloc_lines + filevec[1].alloc_lines + 1;
659 if (int(PTRDIFF_MAX / sizeof *equivs) <= equivs_alloc) 659 if ((lin)(PTRDIFF_MAX / sizeof *equivs) <= equivs_alloc)
660 xalloc_die (); 660 xalloc_die ();
661 equivs = (equivclass*)xmalloc (equivs_alloc * sizeof *equivs); 661 equivs = (equivclass*)xmalloc (equivs_alloc * sizeof *equivs);
662 /* Equivalence class 0 is permanently safe for lines that were not 662 /* Equivalence class 0 is permanently safe for lines that were not
663 hashed. Real equivalence classes start at 1. */ 663 hashed. Real equivalence classes start at 1. */
664 equivs_index = 1; 664 equivs_index = 1;