Changeset 2132 for trunk


Ignore:
Timestamp:
Mar 10, 2011, 7:35:02 AM (14 years ago)
Author:
mmc
Message:

Fixed the Diffview widget to work with large diff files. There was a
problem with the way pointers were handled that manifested with large
diff strings that required reallocation of memory. Fixed to use integer
indices now instead of pointers, so the pointer values can't go stale.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/src/RpDiffview.c

    r2125 r2132  
    8383    int index1;                 /* index in buffer #1 */
    8484    int index2;                 /* index in buffer #2 */
    85     struct subseq *subseqPtr;   /* LCS indices for buffer #1 */
     85    int next;                   /* next candidate match in the chain */
    8686} DiffviewSubseq;
    8787
     
    23892389    Tcl_HashEntry *entryPtr;
    23902390    Tcl_DString buffer;
    2391     DiffviewSubseq *K, *newK, *candidate, newCandidate; int Kmax; int Klen;
     2391    DiffviewSubseq *K, *newK, newCandidate; int Kmax; int Klen;
    23922392    Tcl_Obj *listPtr, **objv;
    2393     int i, j, subseqLen, longestMatch, max, min, mid, midval, sLen, del;
     2393    int i, j, candidateIdx, subseqLen, longestMatch;
     2394    int max, min, mid, midval, sLen, del;
    23942395    int len, created, o, objc, index1, *lcsIndex1, index2, *lcsIndex2;
    23952396    char *key;
     
    24282429    K[0].index1 = -1;
    24292430    K[0].index2 = -1;
    2430     K[0].subseqPtr = NULL;
     2431    K[0].next = -1;
    24312432    K[1].index1 = limsPtr1->numLines;
    24322433    K[1].index2 = limsPtr2->numLines;
    2433     K[1].subseqPtr = NULL;
     2434    K[1].next = -1;
    24342435    Klen = 2;
    24352436    longestMatch = 0;
     
    24482449        if (entryPtr) {
    24492450            subseqLen = 0;
    2450             candidate = &K[0];
     2451            candidateIdx = 0;
    24512452
    24522453            listPtr = (Tcl_Obj*)Tcl_GetHashValue(entryPtr);
     
    24892490                 */
    24902491                if (subseqLen >= 0) {
    2491                     K[subseqLen].index1    = candidate->index1;
    2492                     K[subseqLen].index2    = candidate->index2;
    2493                     K[subseqLen].subseqPtr = candidate->subseqPtr;
     2492                    if (candidateIdx >= 0) {
     2493                        K[subseqLen].index1 = K[candidateIdx].index1;
     2494                        K[subseqLen].index2 = K[candidateIdx].index2;
     2495                        K[subseqLen].next   = K[candidateIdx].next;
     2496                    } else {
     2497                        K[subseqLen].index1 = newCandidate.index1;
     2498                        K[subseqLen].index2 = newCandidate.index2;
     2499                        K[subseqLen].next   = newCandidate.next;
     2500                    }
    24942501                }
    24952502                newCandidate.index1 = i;
    24962503                newCandidate.index2 = j;
    2497                 newCandidate.subseqPtr = &K[sLen];
    2498                 candidate = &newCandidate;
     2504                newCandidate.next = sLen;
     2505                candidateIdx = -1;  /* use newCandidate info */
    24992506                subseqLen = sLen + 1;
    25002507
     
    25122519                        K = newK;
    25132520                    }
    2514                     K[Klen].index1    = K[Klen-1].index1;
    2515                     K[Klen].index2    = K[Klen-1].index2;
    2516                     K[Klen].subseqPtr = K[Klen-1].subseqPtr;
     2521                    K[Klen].index1 = K[Klen-1].index1;
     2522                    K[Klen].index2 = K[Klen-1].index2;
     2523                    K[Klen].next   = K[Klen-1].next;
    25172524                    Klen++;
    25182525
     
    25232530
    25242531            /* put the last candidate into the array */
    2525             K[subseqLen].index1    = candidate->index1;
    2526             K[subseqLen].index2    = candidate->index2;
    2527             K[subseqLen].subseqPtr = candidate->subseqPtr;
     2532            if (candidateIdx >= 0) {
     2533                K[subseqLen].index1 = K[candidateIdx].index1;
     2534                K[subseqLen].index2 = K[candidateIdx].index2;
     2535                K[subseqLen].next   = K[candidateIdx].next;
     2536            } else {
     2537                K[subseqLen].index1 = newCandidate.index1;
     2538                K[subseqLen].index2 = newCandidate.index2;
     2539                K[subseqLen].next   = newCandidate.next;
     2540            }
    25282541        }
    25292542    }
     
    25382551    len = longestMatch;
    25392552
    2540     candidate = &K[longestMatch];
    2541     while (candidate->index1 >= 0) {
    2542         longestMatch--;
    2543         lcsIndex1[longestMatch] = candidate->index1;
    2544         lcsIndex2[longestMatch] = candidate->index2;
    2545         candidate = candidate->subseqPtr;
     2553    candidateIdx = longestMatch;
     2554    while (K[candidateIdx].index1 >= 0) {
     2555        if (longestMatch-- < 0) {
     2556            Tcl_Panic("internal mismatch in diff algorithm");
     2557        }
     2558        lcsIndex1[longestMatch] = K[candidateIdx].index1;
     2559        lcsIndex2[longestMatch] = K[candidateIdx].index2;
     2560        candidateIdx = K[candidateIdx].next;
    25462561    }
    25472562
Note: See TracChangeset for help on using the changeset viewer.