fun patch_splitMax(patches: LinkedList<javax.sound.midi.Patch?>) { val patch_size: Short = Match_MaxBits var precontext: String var postcontext: String var patch: javax.sound.midi.Patch var start1: Int var start2: Int var empty: Boolean var diff_type: Operation var diff_text: String val pointer: MutableListIterator<javax.sound.midi.Patch?> = patches.listIterator() var bigpatch: javax.sound.midi.Patch? = if (pointer.hasNext()) pointer.next() else null while (bigpatch != null) { if (bigpatch.length1 <= Match_MaxBits) { bigpatch = if (pointer.hasNext()) pointer.next() else null continue } pointer.remove() start1 = bigpatch.start1 start2 = bigpatch.start2 precontext = "" while (!bigpatch.diffs.isEmpty()) { patch = javax.sound.midi.Patch() empty = true patch.start1 = start1 - precontext.length patch.start2 = start2 - precontext.length if (precontext.length != 0) { patch.length2 = precontext.length patch.length1 = patch.length2 patch.diffs.add( jdk.internal.org.jline.utils.DiffHelper.Diff( Operation.EQUAL, precontext ) ) } while (!bigpatch.diffs.isEmpty() && patch.length1 < patch_size - Patch_Margin) { diff_type = bigpatch.diffs.getFirst().operation diff_text = bigpatch.diffs.getFirst().text if (diff_type === Operation.INSERT) { patch.length2 += diff_text.length start2 += diff_text.length patch.diffs.addLast(bigpatch.diffs.removeFirst()) empty = false } else if (diff_type === Operation.DELETE && patch.diffs.size() === 1 && patch.diffs.getFirst().operation === Operation.EQUAL && diff_text.length > 2 * patch_size) { patch.length1 += diff_text.length start1 += diff_text.length empty = false patch.diffs.add,  dk.internal.org.jline.utils.DiffHelper.Diff( diff_type, diff_text ) ) bigpatch.diffs.removeFirst() } else { diff_text = diff_text.substring( 0, Math.min(diff_text.length, patch_size - patch.length1 - Patch_Margin) ) patch.length1 += diff_text.length start1 += diff_text.length if (diff_type === Operation.EQUAL) { patch.length2 += diff_text.length start2 += diff_text.length } else { empty = false } patch.diffs.add( jdk.internal.org.jline.utils.DiffHelper.Diff( diff_type, diff_text ) ) if (diff_text == bigpatch.diffs.getFirst().text) { bigpatch.diffs.removeFirst() } else { bigpatch.diffs.getFirst().text = bigpatch.diffs.getFirst().text.substring(diff_text.length) } } } precontext = diff_text2(patch.diffs) precontext = precontext.substring(Math.max(0, precontext.length - Patch_Margin)) if (diff_text1(bigpatch.diffs).length() > Patch_Margin) { postcontext = diff_text1(bigpatch.diffs).substring(0, Patch_Margin) } else { postcontext = diff_text1(bigpatch.diffs) } if (postcontext.length != 0) { patch.length1 += postcontext.lengthpatch.length2 += postcontext.length if (!patch.diffs.isEmpty() && patch.diffs.getLast().operation === Operation.EQUAL) { patch.diffs.getLast().text += postcontext } else { patch.diffs.add( jdk.internal.org.jline.utils.DiffHelper.Diff( Operation.EQUAL, postcontext ) ) } } if (!empty) { pointer.add(patch) } }bigpatch = if (pointer.hasNext()) pointer.next() else null } }
Look through the patches and break up any which are longer than the maximum limit of the match algorithm . Intended to be called only from within patch_apply .