Skip to content

Prefer ArrayList over LinkedList and native array#1334

Closed
belugabehr wants to merge 2 commits intoapache:masterfrom
belugabehr:RFileLinkedList
Closed

Prefer ArrayList over LinkedList and native array#1334
belugabehr wants to merge 2 commits intoapache:masterfrom
belugabehr:RFileLinkedList

Conversation

@belugabehr
Copy link
Contributor

No description provided.

Copy link
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes. The LinkedList was probably preferable for the deepCopies, though.


List<LocalityGroupReader> readers = (useSample) ? r.sampleReaders : r.readers;
for (LocalityGroupReader reader : readers) {
LocalityGroupReader newReader = new LocalityGroupReader(reader);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good opportunity to use var if one were inclined.

Suggested change
LocalityGroupReader newReader = new LocalityGroupReader(reader);
var newReader = new LocalityGroupReader(reader);

}

if (deepCopies.size() != 0)
if (!deepCopies.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated changes, but nice changes to see anyway. I sometimes have my IDE automatically add missing braces for single-statement blocks, but the downside is that they can clutter the review (same with the unrelated change to convert this to isEmpty()). I don't think there' a problem here... the changes in this PR are simple enough to understand, and these are nice changes to see.

}

@Deprecated
public LocalityGroupContext(LocalityGroup[] groups) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't public API. It's internal only, so if we're not using it internally, we don't need to keep it around deprecated for any user code. It can just be deleted outright.

currentReaders = new ArrayList<>(size);

deepCopies = new LinkedList<>();
deepCopies = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only ever do add() on this, which can cause problems on certain system patterns which use a lot of deepCopies, if it results in array resizing. LinkedList is probably better here for those use cases, and not worse for other use cases. I'd leave this one the way it was.

this.currentReaders[i].setInterruptFlag(r.interruptFlag);
}

List<LocalityGroupReader> readers = (useSample) ? r.sampleReaders : r.readers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement to simplify the following loop.

public LocalityGroupIterator(LocalityGroup[] groups) {
super(groups.length);
this.lgContext = new LocalityGroupContext(groups);
this.lgContext = new LocalityGroupContext(Arrays.asList(groups));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this system iterator is also not public API, I wonder if there's something we can do here to pass this in as a list initially, rather than as an array that we have to convert. This could also be done in subsequent work. What do you think, @belugabehr ? Is it worth going down the rabbit hole a bit further on this one, or doing in a future change?

@ctubbsii
Copy link
Member

ctubbsii commented Aug 5, 2020

There has been no response in almost 11 months since the last code review feedback, and the PR now has merge conflicts. I'm closing this for now. Please feel free to re-open or re-submit against the main branch if there is still an interest in making these changes.

@ctubbsii ctubbsii closed this Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants