Skip to content

Don't allocate unnecessary annotation arrays in IonValueLite's copy constructor #1051

@tgregg

Description

@tgregg

https://github.com/amazon-ion/ion-java/blob/master/src/main/java/com/amazon/ion/impl/lite/IonValueLite.java#L305

Currently, this array is allocated even in the following situations:

  1. When the array to be copied has length 0
  2. When the array to be copied has length > 0 but only null elements

This should be optimized by waiting to allocate the array until at least one non-null element is found, and using a constant SymbolToken[0] when no annotations are present.

Further, we should double-check the logic that causes an array with length > 0 and only null elements to exist, to make sure it is not being wastefully over-allocated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions