JetBrains / JetBrains/mapper

Inefficient Usage of ArrayList and TreeMap

Open
#220 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
53
Forks
22
PR merge metrics
No merged PRs in 30d

Description

Hi,
We find that there are several ArrayList objects which are not manipulated by random access. Due to the memory reallocation triggered in the successive insertions, the time complexity of add method of ArrayList is amortized O(1). We notice that these objects are only used for traversal, the retrieval, and removal of the first or the last element.

This functionality can be implemented by LinkedList. Moreover, the insertion of LinkedList is strictly O(1) time complexity because no memory reallocation occurs.

Meanwhile, we also found several TreeMap objects which are not necessary to maintain the key order relation. To achieve the same functionality, HashHap is enough. The replacement can also reduce the time cost in the modification of the map objects.

We discovered the above inefficient usage of containers by our tool Ditto. The patch is submitted in #219. Could you please check and accept it? We have tested the patch on our PC. The patched program works well.

Bests

Ditto

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.