this should be faster for strings with fewer escapes, but probably slower for many escapes.
438183
private void readStringChars2(CharArr arr, int middle) throws IOException {
    if (stringTerm == 0) {
      readStringBare(arr);
      return;
    }

    char terminator = (char) stringTerm;

    for (;;) {
      if (middle>=end) {
        arr.write(buf,start,middle-start);
        start=middle;
        getMore();
        middle=start;
      }
      int ch = buf[middle++];
      if (ch == terminator) {
        int len = middle-start-1;        
        if (len>0) arr.write(buf,start,len);
        start=middle;
        return;
      } else if (ch=='\\') {
        int len = middle-start-1;
        if (len>0) arr.write(buf,start,len);
        start=middle;
        arr.write(readEscapedChar());
        middle=start;
      }
    }
  }
1165092
private void append2slowstr() {
    // In case of all NAs and then a string, convert NAs to string NAs
    if (_xs != null) {
      _xs = null; _ms = null;
      alloc_str_indices(_sparseLen);
      Arrays.fill(_is,-1);
    }

    if(_is != null && _is.length > 0){
      // Check for sparseness
      if(_id == null){
        int nzs = 0; // assume one non-null for the element currently being stored
        for( int i:_is) if( i != -1 ) ++nzs;
        if( (nzs+1)*_sparseRatio < _len)
          set_sparse(nzs, Compress.NA);
      } else {
        if((_sparseRatio*(_sparseLen) >> 2) > _len)  cancel_sparse();
        else _id = MemoryManager.arrayCopyOf(_id,_sparseLen<<1);
      }

      _is = MemoryManager.arrayCopyOf(_is, _sparseLen<<1);
      /* initialize the memory extension with -1s */
      for (int i = _sparseLen; i < _is.length; i++) _is[i] = -1;
    } else {
      _is = MemoryManager.malloc4 (4);
        /* initialize everything with -1s */
      for (int i = 0; i < _is.length; i++) _is[i] = -1;
      if (sparseZero()||sparseNA()) alloc_indices(4);
    }
    assert _sparseLen == 0 || _is.length > _sparseLen:"_ls.length = " + _is.length + ", _len = " + _sparseLen;

  }
1013367
def deflate_long(n, add_sign_padding=True):
    ""
    # after much testing, this algorithm was deemed to be the fastest
    s = ''
    n = long(n)
    while (n != 0) and (n != -1):
        s = struct.pack('>I', n & 0xffffffffL) + s
        n = n >> 32
    # strip off leading zeros, FFs
    for i in enumerate(s):
        if (n == 0) and (i[1] != '\000'):
            break
        if (n == -1) and (i[1] != '\xff'):
            break
    else:
        # degenerate case, n was either 0 or -1
        i = (0,)
        if n == 0:
            s = '\000'
        else:
            s = '\xff'
    s = s[i[0]:]
    if add_sign_padding:
        if (n == 0) and (ord(s[0]) >= 0x80):
            s = '\x00' + s
        if (n == -1) and (ord(s[0]) < 0x80):
            s = '\xff' + s
    return s
672316
private static String processUnicodeEscapes(String value) {
    while (value.contains("\\")) {
      int escapeStart = value.indexOf('\\');
      try {
        if (value.charAt(escapeStart + 1) != 'u') {
          return null;
        }

        String hexDigits;
        int escapeEnd;
        if (value.charAt(escapeStart + 2) != '{') {
          // Simple escape with exactly four hex digits: \\uXXXX
          escapeEnd = escapeStart + 6;
          hexDigits = value.substring(escapeStart + 2, escapeEnd);
        } else {
          // Escape with braces can have any number of hex digits: \\u{XXXXXXX}
          escapeEnd = escapeStart + 3;
          while (Character.digit(value.charAt(escapeEnd), 0x10) >= 0) {
            escapeEnd++;
          }
          if (value.charAt(escapeEnd) != '}') {
            return null;
          }
          hexDigits = value.substring(escapeStart + 3, escapeEnd);
          escapeEnd++;
        }
        // TODO(mattloring): Allow code points greater than the size of a char
        char ch = (char) Integer.parseInt(hexDigits, 0x10);
        if (!isIdentifierPart(ch)) {
          return null;
        }
        value = value.substring(0, escapeStart) + ch + value.substring(escapeEnd);
      } catch (NumberFormatException | StringIndexOutOfBoundsException e) {
        return null;
      }
    }
    return value;
  }
1070892
def normalize_string_keys(old):
    """"""
    new = {}
    for key, value in old.items():
        if isinstance(key, bytes_):
            new[key.decode('utf8')] = value
        else:
            new[key] = value
    return new
831638
function stringRepeatRep(s, times) {
                var half,
                    val;

                if (times < 1) {
                    val = '';
                } else if (times % 2) {
                    val = stringRepeatRep(s, times - 1) + s;
                } else {
                    half = stringRepeatRep(s, times / 2);
                    val = half + half;
                }

                return val;
            }
187592
public void skip() {
        int we = wEnd;
        if (wOffset == we) { //requires special handling
            //if no variants at 'wOutside',advance pointer and clear
            if (top == null) {
                wOffset++;
                flush();
            }
            //otherwise, if there exist a variant,
            //don't clear(), i.e. allow it to match
            return;
        } else {
            if (we < 0) wOffset = 0;
            else wOffset = we;
        }
        //rflush(); //rflush() works faster on simple regexes (with a small group/branch number)
        flush();
    }
917821
function compareSpecificityStrings(a, b) {
    var l = Math.min(a.length, b.length);
    for (var i = 0; i < l; i += 1) {
        var ai = StringWrapper.charCodeAt(a, i);
        var bi = StringWrapper.charCodeAt(b, i);
        var difference = bi - ai;
        if (difference != 0) {
            return difference;
        }
    }
    return a.length - b.length;
}
1357078
def to_lower(self, string):
        ""
        value = None
        try:
            value = string.lower()
        except AttributeError:
            value = ""
        finally:
            return value
1078467
function fast(source) {
        var i = source.length;

        while (i--) {
          combinations.push(source.slice(0, i + 1));
          if (i === 1) fast(source.slice(i));
        }

        return combinations;
      }
159234
public int compareTo(OffsetCharSequence other) {
        int len1 = length();
        int len2 = other.length();
        int lim = Math.min(len1, len2);

        for (int i = 0; i  < lim; i++) {
            char c1 = charAt(i);
            char c2 = other.charAt(i);
            if (c1 != c2) {
                return c1 - c2;
            }
        }
        return len1 - len2;
    }
388960
function stringSize(string) {
      if (!(string && reHasComplexSymbol.test(string))) {
        return string.length;
      }
      var result = reComplexSymbol.lastIndex = 0;
      while (reComplexSymbol.test(string)) {
        result++;
      }
      return result;
    }
387050
function strRepeat(str, n) {
    var res = '';
    do {
        if (n & 1) {
            res += str;
        }

        str += str;
    } while (n = n >> 1);

    return res;
}
300136
protected function optimizeTrailingText()
	{
		$strings = $this->getTextContent('lastChild');
		if (empty($strings))
		{
			return;
		}

		// Flip the strings before computing the prefix length to get the suffix length
		$len = $this->getPrefixLength(array_map('strrev', $strings));
		if ($len)
		{
			$this->adjustTextNodes('lastChild', 0, -$len);
			$this->choose->parentNode->insertBefore(
				$this->createText(substr($strings[0], -$len)),
				$this->choose->nextSibling
			);
		}
	}
422445
def safe_mult(a, b):
    """"""
    if isinstance(a, str) and isinstance(b, int) and len(a) * b > MAX_STR_LEN:
        raise RuntimeError("String length exceeded, max string length is {}".format(MAX_STR_LEN))
    return a * b
446257
private V getBest(int t, String s, int offset, int len) {
        int node = t;
        int end = offset + len;
        loop:
        while (offset < end) {
            char c = s.charAt(offset++);
            len--;
            if (isCaseInsensitive() && c < 128)
                c = StringUtils.lowercases[c];

            while (true) {
                int row = ROW_SIZE * t;
                char n = _tree[row];
                int diff = n - c;

                if (diff == 0) {
                    t = _tree[row + EQ];
                    if (t == 0)
                        break loop;

                    // if this node is a match, recurse to remember
                    if (_key[t] != null) {
                        node = t;
                        V better = getBest(t, s, offset, len);
                        if (better != null)
                            return better;
                    }
                    break;
                }

                t = _tree[row + hilo(diff)];
                if (t == 0)
                    break loop;
            }
        }
        return (V) _value[node];
    }
121827
public final String escape(String in) {
        if (in == null)
            return "";

        if (in.trim()
                  .equals(""))
            return in;

        if (in.trim()
                  .length() == 0)
            return in;

        in = in.replaceAll(
                "&",
                "&amp;"
            );
        in = in.replaceAll(
                "<",
                "&lt;"
            );
        in = in.replaceAll(
                ">",
                "&gt;"
            );

        StringBuffer result = new StringBuffer();
        char chars[] = in.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            if ((chars[i] >= 127) && (chars[i] < 160)) {
                chars[i] = 32;
                result.append(chars[i]);
            } else if (chars[i] == 160) {
                result.append("&#160;");
            } else if (chars[i] == 9) {
                result.append(" ");
            } else if ((chars[i] < 32) && (chars[i] != 9) && (chars[i] != 10)
                    && (chars[i] != 13)
            ) {
                chars[i] = 32;
                result.append(chars[i]);
            } else {
                result.append(chars[i]);
            }
        }

        in = result.toString();

        return in;
    }