Querz / NBT

A java implementation of the NBT protocol, including a way to implement custom tags.
MIT License
183 stars 48 forks source link

Add initial capacity to List and Compound tags #60

Closed urielsalis closed 3 years ago

urielsalis commented 3 years ago

Background

While running some profiling test on some high performance code using the library we found some simple optimizations :)

Problem

Resizing the backing collections for CompoundTag and ListTag can be expensive(Its a O(N) operation)

Goal

Add initial capacity constructors to both classes, so if you already know the size you can create it directly with that size and avoid the resizing :D

Implementation

Add new constructors that set the initial capacity

Caveats

None.

Further considerations

None.

ToDo list

None.

urielsalis commented 3 years ago

Intellij autoformatter did some extra changes, let me know if you want me to revert them or its fine to leave them as is :)

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.07%) to 78.283% when pulling 4021aaae1b62c68dd4e9f6b77e9d3b7f0471f2fc on urielsalis:add-initial-capacity into f05f37f6675e81b5263a31f660e65895283b05d7 on Querz:master.

Querz commented 3 years ago

lgtm