MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / patch_splitMax

Method patch_splitMax

3rdparty/diff-match-patch/diff_match_patch.cpp:1920–2021  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1918
1919
1920void diff_match_patch::patch_splitMax(QList<Patch> &patches) {
1921 short patch_size = Match_MaxBits;
1922 QString precontext, postcontext;
1923 Patch patch;
1924 int start1, start2;
1925 bool empty;
1926 Operation diff_type;
1927 QString diff_text;
1928 QMutableListIterator<Patch> pointer(patches);
1929 Patch bigpatch;
1930
1931 if (pointer.hasNext()) {
1932 bigpatch = pointer.next();
1933 }
1934
1935 while (!bigpatch.isNull()) {
1936 if (bigpatch.length1 <= patch_size) {
1937 bigpatch = pointer.hasNext() ? pointer.next() : Patch();
1938 continue;
1939 }
1940 // Remove the big old patch.
1941 pointer.remove();
1942 start1 = bigpatch.start1;
1943 start2 = bigpatch.start2;
1944 precontext = "";
1945 while (!bigpatch.diffs.isEmpty()) {
1946 // Create one of several smaller patches.
1947 patch = Patch();
1948 empty = true;
1949 patch.start1 = start1 - precontext.length();
1950 patch.start2 = start2 - precontext.length();
1951 if (!precontext.isEmpty()) {
1952 patch.length1 = patch.length2 = precontext.length();
1953 patch.diffs.append(Diff(EQUAL, precontext));
1954 }
1955 while (!bigpatch.diffs.isEmpty()
1956 && patch.length1 < patch_size - Patch_Margin) {
1957 diff_type = bigpatch.diffs.front().operation;
1958 diff_text = bigpatch.diffs.front().text;
1959 if (diff_type == INSERT) {
1960 // Insertions are harmless.
1961 patch.length2 += diff_text.length();
1962 start2 += diff_text.length();
1963 patch.diffs.append(bigpatch.diffs.front());
1964 bigpatch.diffs.removeFirst();
1965 empty = false;
1966 } else if (diff_type == DELETE && patch.diffs.size() == 1
1967 && patch.diffs.front().operation == EQUAL
1968 && diff_text.length() > 2 * patch_size) {
1969 // This is a large deletion. Let it pass in one chunk.
1970 patch.length1 += diff_text.length();
1971 start1 += diff_text.length();
1972 empty = false;
1973 patch.diffs.append(Diff(diff_type, diff_text));
1974 bigpatch.diffs.removeFirst();
1975 } else {
1976 // Deletion or equality. Only take as much as we can stomach.
1977 diff_text = diff_text.left(std::min(diff_text.length(),

Callers

nothing calls this directly

Calls 12

PatchClass · 0.85
frontMethod · 0.80
leftMethod · 0.80
insertMethod · 0.80
DiffClass · 0.70
nextMethod · 0.45
isNullMethod · 0.45
removeMethod · 0.45
isEmptyMethod · 0.45
lengthMethod · 0.45
appendMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected