Thread: [pgjdbc/pgjdbc] c84e62: Utf 8 encoding optimizations (#1444)

[pgjdbc/pgjdbc] c84e62: Utf 8 encoding optimizations (#1444)

From
Brett Okken
Date:
  Branch: refs/heads/master
  Home:   https://github.com/pgjdbc/pgjdbc
  Commit: c84e62efa5b98323562753e45fbf0d974eaca483
      https://github.com/pgjdbc/pgjdbc/commit/c84e62efa5b98323562753e45fbf0d974eaca483
  Author: Brett Okken <brett.okken.os@gmail.com>
  Date:   2020-01-16 (Thu, 16 Jan 2020)

  Changed paths:
    A pgjdbc/src/main/java/org/postgresql/core/ByteOptimizedUTF8Encoder.java
    A pgjdbc/src/main/java/org/postgresql/core/CharOptimizedUTF8Encoder.java
    M pgjdbc/src/main/java/org/postgresql/core/Encoding.java
    A pgjdbc/src/main/java/org/postgresql/core/OptimizedUTF8Encoder.java
    R pgjdbc/src/main/java/org/postgresql/core/UTF8Encoding.java
    A pgjdbc/src/test/java/org/postgresql/core/UTF8EncodingTest.java
    M pgjdbc/src/test/java/org/postgresql/test/jdbc2/Jdbc2TestSuite.java

  Log Message:
  -----------
  Utf 8 encoding optimizations (#1444)

* fix: Correct typo weather to whether

* misc: Change internal Encoding.testAsciiNumbers(...) to be static

* perf: Enhance Encoding constructor to allow skipping of ASCII number compatibility test

Adds a two parameter constructor to Encoding to allow sub classes to specify whether their
known ASCII compatability so as to skip testing. The only usage of it is the UTF8Encoding
which is changed to use the new constructor.

* fix: limit size of char[] for utf-8 decoding

Also optimize for java 9+ byte[] backed strings

* fix: limit size of char[] for utf-8 decoding

address style issues

* fix: limit size of char[] for utf-8 decoding

address style issues

* fix: limit size of char[] for utf-8 decoding

use existing JavaVersion enum to pick implementation
add unit test string values
more consistency between byte and char based implementations

* fix: limit size of char[] for utf-8 decoding

fix backwards comparison
add more strings to unit test

* fix: limit size of char[] for utf-8 decoding

Move to using new String(byte[], int, int, Charset) rather than custom
decoding for jre newer than 1.8.

* fix: limit size of char[] for utf-8 decoding

Back to custom utf-8 decoding for performance gains while validating

* javadoc

* put test back into test suite

* avoid creating an unnecessary `char[]` when growing cached array

Co-authored-by: Sehrope Sarkuni <sehrope@jackdb.com>
Co-authored-by: Dave Cramer <davecramer@gmail.com>