-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize control code #13354
Merged
Merged
Optimize control code #13354
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d1cee54
Reserve memory m_controls before filling it in loop
JoergAtGithub ea4fb6a
Moved duplicated code in new private function setBehavior
JoergAtGithub 829ae91
Memory alignment of ControlDoublePrivate to reduce size from 464 byte…
JoergAtGithub a1b5c25
Add comment about memory alignment
JoergAtGithub 69e1231
Renamed setBehavior to updateBehavior and added a real setBehavior fu…
JoergAtGithub 891bedb
Merge remote-tracking branch 'upstream/main' into optimize_control_code
JoergAtGithub 0fb3ed0
Merge remote-tracking branch 'upstream/main' into optimize_control_code
JoergAtGithub e51a92e
Removed unecessary keyword enum
JoergAtGithub 45ef076
Removed redundant cast
JoergAtGithub dec4a9d
Renamed enum entries accrding cpp core guidelines
JoergAtGithub 6728c91
Updated buttonModeToString to use QStringLiteral and added DEBUG_ASSE…
JoergAtGithub 6c49909
Moved handling of default path out of the switch statement
JoergAtGithub abc798a
Use namespace for control button mode
JoergAtGithub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
// required for Qt-Macros | ||
#include <qobjectdefs.h> | ||
|
||
namespace mixxx { | ||
|
||
namespace control { | ||
|
||
Q_NAMESPACE | ||
|
||
enum class ButtonMode { | ||
Push, | ||
Toggle, | ||
PowerWindow, | ||
LongPressLatching, | ||
Trigger | ||
}; | ||
|
||
Q_ENUM_NS(ButtonMode); | ||
|
||
} // namespace control | ||
} // namespace mixxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,40 @@ | ||
/*************************************************************************** | ||
controlpushbutton.h - description | ||
------------------- | ||
begin : Wed Feb 20 2002 | ||
copyright : (C) 2002 by Tue and Ken Haste Andersen | ||
email : | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef CONTROLPUSHBUTTON_H | ||
#define CONTROLPUSHBUTTON_H | ||
#pragma once | ||
|
||
#include "control/controlbuttonmode.h" | ||
#include "control/controlobject.h" | ||
|
||
/** | ||
*@author Tue and Ken Haste Andersen | ||
*/ | ||
|
||
class ControlPushButton : public ControlObject { | ||
Q_OBJECT | ||
public: | ||
enum ButtonMode { | ||
PUSH = 0, | ||
TOGGLE, | ||
POWERWINDOW, | ||
LONGPRESSLATCHING, | ||
TRIGGER, | ||
}; | ||
|
||
static QString buttonModeToString(int mode) { | ||
switch(mode) { | ||
case ControlPushButton::PUSH: | ||
return "PUSH"; | ||
case ControlPushButton::TOGGLE: | ||
return "TOGGLE"; | ||
case ControlPushButton::POWERWINDOW: | ||
return "POWERWINDOW"; | ||
case ControlPushButton::LONGPRESSLATCHING: | ||
return "LONGPRESSLATCHING"; | ||
case ControlPushButton::TRIGGER: | ||
return "TRIGGER"; | ||
default: | ||
return "UNKNOWN"; | ||
static QString buttonModeToString(mixxx::control::ButtonMode buttonMode) { | ||
switch (buttonMode) { | ||
case mixxx::control::ButtonMode::Push: | ||
return QStringLiteral("Push"); | ||
case mixxx::control::ButtonMode::Toggle: | ||
return QStringLiteral("Toggle"); | ||
case mixxx::control::ButtonMode::PowerWindow: | ||
return QStringLiteral("PowerWindow"); | ||
case mixxx::control::ButtonMode::LongPressLatching: | ||
return QStringLiteral("LongPressLatching"); | ||
case mixxx::control::ButtonMode::Trigger: | ||
return QStringLiteral("Trigger"); | ||
} | ||
DEBUG_ASSERT(false); | ||
return "Unknown"; | ||
} | ||
|
||
ControlPushButton(const ConfigKey& key, bool bPersist = false, double defaultValue = 0.0); | ||
virtual ~ControlPushButton(); | ||
|
||
inline ButtonMode getButtonMode() const { | ||
inline mixxx::control::ButtonMode getButtonMode() const { | ||
return m_buttonMode; | ||
} | ||
void setButtonMode(enum ButtonMode mode); | ||
void setButtonMode(mixxx::control::ButtonMode mode); | ||
void setStates(int num_states); | ||
void setBehavior(mixxx::control::ButtonMode mode, int num_states); | ||
|
||
private: | ||
enum ButtonMode m_buttonMode; | ||
void updateBehavior(); | ||
enum mixxx::control::ButtonMode m_buttonMode; | ||
int m_iNoStates; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we protect that for get cluttered again? Maybe define regions via comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could try
-Wpadded
https://developers.redhat.com/blog/2016/06/01/how-to-avoid-wasting-megabytes-of-memory-a-few-bytes-at-a-time#toolsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried -Wpadded on CI, but it does not only warn about padding inside of the data structure, but also if the overall size is not matching the byte alignment size, e.g. any class with 6 bytes would need to filled up with 2 explicit padding bytes.
I found also a currently unused macro in
mixxx/src/util/platform.h
Line 15 in 15b4444
Maybe someone on Linux could try: https://linux.die.net/man/1/pahole
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay that makes sense I guess when the compiler expects you to nest these packed data structures. The only other potential solution I found was to generate two versions of the type, one packed (potentially with suboptimal alignment and then
static_assert(sizeof(T) == sizeof(_T_packed))
(potentially with a bit of rounding to manually account for the overall size). I wouldn't know how to accomplish that without copy pasting or a macro (doing the copy-pasting automatically) though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not over engineer it. Just a comment state informs there reader that the oder of the variables has been chosen to avoid memory gaps due to alignment is probably sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already added:
mixxx/src/control/control.h
Lines 203 to 205 in 6728c91