Skip to content

Conversation

shartte
Copy link
Member

@shartte shartte commented Aug 12, 2024

No description provided.

Copy link

@sh1ftchg sh1ftchg left a comment

Choose a reason for hiding this comment

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

Nothing bad just some minor comments about performance pet peeves. Great work!

panels.render(bgLayer, 0, 0xffffffff);

// Allow all composite widgets to participate in the sprite layer
widgets.drawBackgroundSpriteLayer(bgLayer, getBounds(true), new Point(mouseX - leftPos, mouseY - topPos));

Choose a reason for hiding this comment

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

There's only one mouse and creation of new unmanaged objects like a new Point is not really necessary is it?

var background = style.getBackground();
if (background != null) {
background.dest(offsetX, offsetY).blit(guiGraphics);
widgets.addBackgroundPanels(panels, getBounds(true));

Choose a reason for hiding this comment

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

Store the result of getBounds - excessive cyclic calls are also ill advised as this is used not even 2 lines later.


// Group all slots by semantic. We make the assumption here
// that visually the slots belonging to the same semantic are contiguous.
for (var semantic : menu.getSlotBySemantic().keySet()) {

Choose a reason for hiding this comment

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

Store the menu.getSlotBySemantic() as a local variable (lv) as per the aforementioned advice. it's used a lot and recursive calls are still ill advised.

maxY = Math.max(maxY, backgroundY + backgroundHeight);
}

for (var slot : slots) {

Choose a reason for hiding this comment

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

Is two iterations necessary? Couldn't this pass be done in the previous loop on line 795 and again at line 824? The control flow graph only shows those 2 branch points? Also it's generally bad practice to separate alterations and work as it loses context of where/when it was modified.

Plus you do the exact same instanceof and isActive logic in the aforementioned loop already... Why make it do double work - especially considering that aside from object creation (new) instanceof is the most costly java dynamic.

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