def diff_halfMatch(self, text1, text2):
    """Do the two texts share a substring which is at least half the length of
    the longer text?
    This speedup can produce non-minimal diffs.

    Args:
      text1: First string.
      text2: Second string.

    Returns:
      Five element Array, containing the prefix of text1, the suffix of text1,
      the prefix of text2, the suffix of text2 and the common middle.  Or None
      if there was no match.
    """
    if self.Diff_Timeout <= 0:
      # Don't risk returning a non-optimal diff if we have unlimited time.
      return None
    if len(text1) > len(text2):
      (longtext, shorttext) = (text1, text2)
    else:
      (shorttext, longtext) = (text1, text2)
    if len(longtext) < 4 or len(shorttext) * 2 < len(longtext):
      return None  # Pointless.

    def diff_halfMatchI(longtext, shorttext, i):
      """Does a substring of shorttext exist within longtext such that the
      substring is at least half the length of longtext?
      Closure, but does not reference any external variables.

      Args:
        longtext: Longer string.
        shorttext: Shorter string.
        i: Start index of quarter length substring within longtext.

      Returns:
        Five element Array, containing the prefix of longtext, the suffix of
        longtext, the prefix of shorttext, the suffix of shorttext and the
        common middle.  Or None if there was no match.
      """
      seed = longtext[i:i + len(longtext) // 4]
      best_common = ''
      j = shorttext.find(seed)
      while j != -1:
        prefixLength = self.diff_commonPrefix(longtext[i:], shorttext[j:])
        suffixLength = self.diff_commonSuffix(longtext[:i], shorttext[:j])
        if len(best_common) < suffixLength + prefixLength:
          best_common = (shorttext[j - suffixLength:j] +
              shorttext[j:j + prefixLength])
          best_longtext_a = longtext[:i - suffixLength]
          best_longtext_b = longtext[i + prefixLength:]
          best_shorttext_a = shorttext[:j - suffixLength]
          best_shorttext_b = shorttext[j + prefixLength:]
        j = shorttext.find(seed, j + 1)

      if len(best_common) * 2 >= len(longtext):
        return (best_longtext_a, best_longtext_b,
                best_shorttext_a, best_shorttext_b, best_common)
      else:
        return None

    # First check if the second quarter is the seed for a half-match.
    hm1 = diff_halfMatchI(longtext, shorttext, (len(longtext) + 3) // 4)
    # Check again based on the third quarter.
    hm2 = diff_halfMatchI(longtext, shorttext, (len(longtext) + 1) // 2)
    if not hm1 and not hm2:
      return None
    elif not hm2:
      hm = hm1
    elif not hm1:
      hm = hm2
    else:
      # Both matched.  Select the longest.
      if len(hm1[4]) > len(hm2[4]):
        hm = hm1
      else:
        hm = hm2

    # A half-match was found, sort out the return data.
    if len(text1) > len(text2):
      (text1_a, text1_b, text2_a, text2_b, mid_common) = hm
    else:
      (text2_a, text2_b, text1_a, text1_b, mid_common) = hm
    return (text1_a, text1_b, text2_a, text2_b, mid_common)
dataset/ETHPy150Open JT5D/Alfred-Popclip-Sublime/Sublime Text 2/JsFormat/libs/diff_match_patch/python2/diff_match_patch.py/diff_match_patch.diff_halfMatch/original