410 // newly created string required, see JLS 15.18.1
411 return new String(s2);
412 }
413 if (s2.isEmpty()) {
414 // newly created string required, see JLS 15.18.1
415 return new String(s1);
416 }
417 // start "mixing" in length and coder or arguments, order is not
418 // important
419 long indexCoder = mix(initialCoder(), s1);
420 indexCoder = mix(indexCoder, s2);
421 byte[] buf = newArray(indexCoder);
422 // prepend each argument in reverse order, since we prepending
423 // from the end of the byte array
424 indexCoder = prepend(indexCoder, buf, s2);
425 indexCoder = prepend(indexCoder, buf, s1);
426 return newString(buf, indexCoder);
427 }
428
429 /**
430 * We need some additional conversion for Objects in general, because
431 * {@code String.valueOf(Object)} may return null. String conversion rules
432 * in Java state we need to produce "null" String in this case, so we
433 * provide a customized version that deals with this problematic corner case.
434 */
435 static String stringOf(Object value) {
436 String s;
437 return (value == null || (s = value.toString()) == null) ? "null" : s;
438 }
439
440 private static final long LATIN1 = (long)String.LATIN1 << 32;
441
442 private static final long UTF16 = (long)String.UTF16 << 32;
443
444 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
445
446 /**
447 * Allocates an uninitialized byte array based on the length and coder
448 * information, then prepends the given suffix string at the end of the
449 * byte array before returning it. The calling code must adjust the
|
410 // newly created string required, see JLS 15.18.1
411 return new String(s2);
412 }
413 if (s2.isEmpty()) {
414 // newly created string required, see JLS 15.18.1
415 return new String(s1);
416 }
417 // start "mixing" in length and coder or arguments, order is not
418 // important
419 long indexCoder = mix(initialCoder(), s1);
420 indexCoder = mix(indexCoder, s2);
421 byte[] buf = newArray(indexCoder);
422 // prepend each argument in reverse order, since we prepending
423 // from the end of the byte array
424 indexCoder = prepend(indexCoder, buf, s2);
425 indexCoder = prepend(indexCoder, buf, s1);
426 return newString(buf, indexCoder);
427 }
428
429 /**
430 * Produce a String from a concatenation of single argument, which we
431 * end up using for trivial concatenations like {@code "" + arg}.
432 *
433 * This will always create a new Object to comply with JLS 15.18.1:
434 * "The String object is newly created unless the expression is a
435 * compile-time constant expression".
436 *
437 * @param arg the only argument
438 * @return String resulting string
439 */
440 @ForceInline
441 static String newStringOf(Object arg) {
442 return new String(stringOf(arg));
443 }
444
445 /**
446 * We need some additional conversion for Objects in general, because
447 * {@code String.valueOf(Object)} may return null. String conversion rules
448 * in Java state we need to produce "null" String in this case, so we
449 * provide a customized version that deals with this problematic corner case.
450 */
451 static String stringOf(Object value) {
452 String s;
453 return (value == null || (s = value.toString()) == null) ? "null" : s;
454 }
455
456 private static final long LATIN1 = (long)String.LATIN1 << 32;
457
458 private static final long UTF16 = (long)String.UTF16 << 32;
459
460 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
461
462 /**
463 * Allocates an uninitialized byte array based on the length and coder
464 * information, then prepends the given suffix string at the end of the
465 * byte array before returning it. The calling code must adjust the
|