def patch_splitMax(self, patches):
    """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.

    Args:
      patches: Array of Patch objects.
    """
    patch_size = self.Match_MaxBits
    if patch_size == 0:
      # Python has the option of not splitting strings due to its ability
      # to handle integers of arbitrary precision.
      return
    for x in xrange(len(patches)):
      if patches[x].length1 <= patch_size:
        continue
      bigpatch = patches[x]
      # Remove the big old patch.
      del patches[x]
      x -= 1
      start1 = bigpatch.start1
      start2 = bigpatch.start2
      precontext = ''
      while len(bigpatch.diffs) != 0:
        # Create one of several smaller patches.
        patch = patch_obj()
        empty = True
        patch.start1 = start1 - len(precontext)
        patch.start2 = start2 - len(precontext)
        if precontext:
          patch.length1 = patch.length2 = len(precontext)
          patch.diffs.append((self.DIFF_EQUAL, precontext))

        while (len(bigpatch.diffs) != 0 and
               patch.length1 < patch_size - self.Patch_Margin):
          (diff_type, diff_text) = bigpatch.diffs[0]
          if diff_type == self.DIFF_INSERT:
            # Insertions are harmless.
            patch.length2 += len(diff_text)
            start2 += len(diff_text)
            patch.diffs.append(bigpatch.diffs.pop(0))
            empty = False
          elif (diff_type == self.DIFF_DELETE and len(patch.diffs) == 1 and
              patch.diffs[0][0] == self.DIFF_EQUAL and
              len(diff_text) > 2 * patch_size):
            # This is a large deletion.  Let it pass in one chunk.
            patch.length1 += len(diff_text)
            start1 += len(diff_text)
            empty = False
            patch.diffs.append((diff_type, diff_text))
            del bigpatch.diffs[0]
          else:
            # Deletion or equality.  Only take as much as we can stomach.
            diff_text = diff_text[:patch_size - patch.length1 -
                                  self.Patch_Margin]
            patch.length1 += len(diff_text)
            start1 += len(diff_text)
            if diff_type == self.DIFF_EQUAL:
              patch.length2 += len(diff_text)
              start2 += len(diff_text)
            else:
              empty = False

            patch.diffs.append((diff_type, diff_text))
            if diff_text == bigpatch.diffs[0][1]:
              del bigpatch.diffs[0]
            else:
              bigpatch.diffs[0] = (bigpatch.diffs[0][0],
                                   bigpatch.diffs[0][1][len(diff_text):])

        # Compute the head context for the next patch.
        precontext = self.diff_text2(patch.diffs)
        precontext = precontext[-self.Patch_Margin:]
        # Append the end context for this patch.
        postcontext = self.diff_text1(bigpatch.diffs)[:self.Patch_Margin]
        if postcontext:
          patch.length1 += len(postcontext)
          patch.length2 += len(postcontext)
          if len(patch.diffs) != 0 and patch.diffs[-1][0] == self.DIFF_EQUAL:
            patch.diffs[-1] = (self.DIFF_EQUAL, patch.diffs[-1][1] +
                               postcontext)
          else:
            patch.diffs.append((self.DIFF_EQUAL, postcontext))

        if not empty:
          x += 1
          patches.insert(x, patch)
dataset/ETHPy150Open JT5D/Alfred-Popclip-Sublime/Sublime Text 2/JsFormat/libs/diff_match_patch/python2/diff_match_patch.py/diff_match_patch.patch_splitMax/original