• pjulien's avatar
    Fix for #3849 · 6908826f
    pjulien authored
    This avoids the following allocations over repeated use:
    
    - A ``CharsetEncoder``
    - A byte array to contain the contents of the string
    - A wrapper, via ``ByteBuffer#wrap``, for the previously mentioned byte
      array
    
    This also removes a copy of the temporary byte array.  This extra copy
    is needed because ``String#getBytes`` returns a byte array and its
    length must match the exact size of the contents.
    
    This implementation requires that the builder retain a ``ByteBuffer``
    and ``CharEncoder``.  This is considered slower only for users that
    will only allocate a single string in their buffers or none at all.
    
    The improvement is especially potent if the builder is constantly reused
    by its caller.  This also eliminates the penalty for users that do not
    use strings at all since the cost of allocating these fields is
    now amortized.
    
    The only allocation left in this code is a ``CharBuffer`` wrapper.  It's
    possible to eliminate this allocation using an additional copy but need
    further profiling to see which is the bigger problem.
    6908826f
Name
Last commit
Last update
CMake Loading commit data...
android Loading commit data...
biicode Loading commit data...
build_ide Loading commit data...
docs Loading commit data...
go Loading commit data...
include/flatbuffers Loading commit data...
java Loading commit data...
js Loading commit data...
net/FlatBuffers Loading commit data...
php Loading commit data...
python Loading commit data...
reflection Loading commit data...
samples Loading commit data...
src Loading commit data...
tests Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.travis.yml Loading commit data...
CMakeLists.txt Loading commit data...
CONTRIBUTING Loading commit data...
LICENSE.txt Loading commit data...
biicode.conf Loading commit data...
composer.json Loading commit data...
readme.md Loading commit data...