Skip to content

Commit

Permalink
Add more enum size specifiers
Browse files Browse the repository at this point in the history
To reduce memory usage
  • Loading branch information
cbjeukendrup committed Jan 11, 2025
1 parent fd07813 commit 16b2bec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
28 changes: 14 additions & 14 deletions src/engraving/dom/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#pragma once

#include <unordered_set>
#include <set>

#include "global/containers.h"

Expand All @@ -34,7 +34,7 @@
namespace mu::engraving {
class EngravingItem;

enum class CommandType {
enum class CommandType : signed char {
Unknown = -1,

// Parts
Expand Down Expand Up @@ -148,7 +148,7 @@ enum class CommandType {
//---------------------------------------------------------
// NOTE: keep this in sync with accList array in accidentals.cpp

enum class AccidentalType {
enum class AccidentalType : unsigned char {
///.\{
NONE,
FLAT,
Expand Down Expand Up @@ -331,7 +331,7 @@ enum class AccidentalType {
// NoteType
//---------------------------------------------------------

enum class NoteType {
enum class NoteType : unsigned char {
///.\{
NORMAL = 0,
ACCIACCATURA = 0x1,
Expand All @@ -348,19 +348,19 @@ enum class NoteType {

constexpr NoteType operator|(NoteType t1, NoteType t2)
{
return static_cast<NoteType>(static_cast<int>(t1) | static_cast<int>(t2));
return static_cast<NoteType>(static_cast<unsigned char>(t1) | static_cast<unsigned char>(t2));
}

constexpr bool operator&(NoteType t1, NoteType t2)
{
return static_cast<int>(t1) & static_cast<int>(t2);
return static_cast<unsigned char>(t1) & static_cast<unsigned char>(t2);
}

//---------------------------------------------------------
// HarmonyType
//---------------------------------------------------------

enum class HarmonyType {
enum class HarmonyType : char {
///.\{
STANDARD,
ROMAN,
Expand All @@ -372,7 +372,7 @@ enum class HarmonyType {
// MMRestRangeBracketType
//---------------------------------------------------------

enum class MMRestRangeBracketType {
enum class MMRestRangeBracketType : char {
///.\{
BRACKETS, PARENTHESES, NONE
///\}
Expand All @@ -393,7 +393,7 @@ enum class OffsetType : char {
// Type values determine the order of segments for a given tick
//-------------------------------------------------------------------

enum class SegmentType {
enum class SegmentType : uint16_t {
///.\{
Invalid = 0x0,
BeginBarLine = 0x1,
Expand All @@ -413,20 +413,20 @@ enum class SegmentType {
KeySigAnnounce = 0x1000,
TimeSigAnnounce = 0x2000,
//--
All = -1, ///< Includes all barline types
All = 0xffff, ///< Includes all barline types
/// Alias for `BeginBarLine | StartRepeatBarLine | BarLine | EndBarLine`
BarLineType = BeginBarLine | StartRepeatBarLine | BarLine | EndBarLine,
///\}
};

constexpr SegmentType operator|(const SegmentType t1, const SegmentType t2)
{
return static_cast<SegmentType>(static_cast<int>(t1) | static_cast<int>(t2));
return static_cast<SegmentType>(static_cast<uint16_t>(t1) | static_cast<uint16_t>(t2));
}

constexpr bool operator&(const SegmentType t1, const SegmentType t2)
{
return static_cast<int>(t1) & static_cast<int>(t2);
return static_cast<uint16_t>(t1) & static_cast<uint16_t>(t2);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -496,14 +496,14 @@ enum class TripletFeelType : char {
SCOTTISH_16TH
};

enum class GuitarBendType {
enum class GuitarBendType : char {
BEND,
PRE_BEND,
GRACE_NOTE_BEND,
SLIGHT_BEND,
};

enum class GuitarBendShowHoldLine {
enum class GuitarBendShowHoldLine : char {
AUTO,
SHOW,
HIDE,
Expand Down
60 changes: 30 additions & 30 deletions src/engraving/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using semitone_t = int8_t;
/// of elements on the canvas.
/// Note: keep in sync with array in TConv
//-------------------------------------------------------------------
enum class ElementType {
enum class ElementType : unsigned char {
///.\{
INVALID = 0,
BRACKET_ITEM,
Expand Down Expand Up @@ -253,21 +253,21 @@ enum class OrnamentStyle : char {
};

// P_TYPE::GLISS_STYLE
enum class GlissandoStyle {
enum class GlissandoStyle : char {
CHROMATIC, WHITE_KEYS, BLACK_KEYS, DIATONIC, PORTAMENTO
};

// --- Layout ---

// P_TYPE::ALIGN
enum class AlignV {
enum class AlignV : char {
TOP,
VCENTER,
BOTTOM,
BASELINE
};

enum class AlignH {
enum class AlignH : char {
LEFT,
RIGHT,
HCENTER
Expand Down Expand Up @@ -300,12 +300,12 @@ struct Align {
};

// P_TYPE::PLACEMENT_V
enum class PlacementV {
enum class PlacementV : char {
ABOVE, BELOW
};

// P_TYPE::PLACEMENT_H
enum class PlacementH {
enum class PlacementH : char {
LEFT, CENTER, RIGHT
};

Expand All @@ -315,7 +315,7 @@ enum class TextPlace : char {
};

// P_TYPE::DIRECTION
enum class DirectionV {
enum class DirectionV : char {
AUTO, UP, DOWN
};

Expand All @@ -337,7 +337,7 @@ enum class AutoOnOff : char {
};

//! Note: from lowest to highest priority
enum class VoiceAssignment {
enum class VoiceAssignment : char {
ALL_VOICE_IN_INSTRUMENT,
ALL_VOICE_IN_STAFF,
CURRENT_VOICE_ONLY
Expand Down Expand Up @@ -382,7 +382,7 @@ struct DurationTypeWithDots
// --- Types ---

// P_TYPE::LAYOUTBREAK_TYPE
enum class LayoutBreakType {
enum class LayoutBreakType : char {
PAGE, LINE, SECTION, NOBREAK
};

Expand Down Expand Up @@ -680,7 +680,7 @@ enum class ArpeggioType : unsigned char {
NORMAL, UP, DOWN, BRACKET, UP_STRAIGHT, DOWN_STRAIGHT
};

enum class IntervalStep {
enum class IntervalStep : char {
UNISON,
SECOND,
THIRD,
Expand All @@ -691,7 +691,7 @@ enum class IntervalStep {
OCTAVE
};

enum class IntervalType {
enum class IntervalType : char {
AUTO,
AUGMENTED,
MAJOR,
Expand Down Expand Up @@ -737,7 +737,7 @@ struct OrnamentInterval

static const OrnamentInterval DEFAULT_ORNAMENT_INTERVAL = OrnamentInterval(IntervalStep::SECOND, IntervalType::AUTO);

enum class OrnamentShowAccidental {
enum class OrnamentShowAccidental : char {
DEFAULT,
ANY_ALTERATION,
ALWAYS,
Expand All @@ -757,7 +757,7 @@ enum class PartialSpannerDirection : signed char {
/// Must be in sync with textStyles (in textstyle.cpp)
//-------------------------------------------------------------------
// P_TYPE::TEXT_STYLE
enum class TextStyleType {
enum class TextStyleType : unsigned char {
DEFAULT,

// Page-oriented styles
Expand Down Expand Up @@ -843,14 +843,14 @@ enum class TextStyleType {
IGNORED_TYPES // used for types no longer relevant (mainly Figured bass text type)
};

enum class AnnotationCategory {
enum class AnnotationCategory : signed char {
Undefined = -1,
TempoAnnotation,
PlayingAnnotation,
Other,
};

enum class PlayingTechniqueType {
enum class PlayingTechniqueType : signed char {
Undefined = -1,
Natural,
Pizzicato,
Expand All @@ -870,7 +870,7 @@ enum class PlayingTechniqueType {
JazzTone,
};

enum class GradualTempoChangeType {
enum class GradualTempoChangeType : signed char {
Undefined = -1,
Accelerando,
Allargando,
Expand Down Expand Up @@ -917,7 +917,7 @@ enum class AccidentalVal : signed char {
MAX = SHARP3
};

enum class FermataType {
enum class FermataType : signed char {
Undefined = -1,
VeryShort,
Short,
Expand All @@ -933,7 +933,7 @@ enum class ChordLineType : char {
PLOP, SCOOP
};

enum class SlurStyleType {
enum class SlurStyleType : signed char {
Undefined = -1,
Solid,
Dotted,
Expand Down Expand Up @@ -998,11 +998,11 @@ enum class BracketType : signed char {
using InstrumentTrackIdList = std::vector<InstrumentTrackId>;
using InstrumentTrackIdSet = std::unordered_set<InstrumentTrackId>;

enum EmbellishmentType {};
enum EmbellishmentType : unsigned char {};

enum DrumNum {};
enum DrumNum : unsigned char {};

enum class GlissandoType {
enum class GlissandoType : char {
STRAIGHT, WAVY
};

Expand Down Expand Up @@ -1049,7 +1049,7 @@ enum class VibratoType : char {
GUITAR_VIBRATO, GUITAR_VIBRATO_WIDE, VIBRATO_SAWTOOTH, VIBRATO_SAWTOOTH_WIDE
};

enum class ArticulationTextType {
enum class ArticulationTextType : char {
NO_TEXT,
TAP,
SLAP,
Expand All @@ -1060,28 +1060,28 @@ enum class LyricsSyllabic : char {
SINGLE, BEGIN, END, MIDDLE
};

enum class LyricsDashSystemStart {
enum class LyricsDashSystemStart : char {
STANDARD,
UNDER_HEADER,
UNDER_FIRST_NOTE
};

enum class NoteLineEndPlacement {
enum class NoteLineEndPlacement : char {
LEFT_EDGE,
OFFSET_ENDS,
};

enum class SpannerSegmentType {
enum class SpannerSegmentType : char {
SINGLE, BEGIN, MIDDLE, END
};

enum class TiePlacement {
enum class TiePlacement : char {
AUTO,
INSIDE,
OUTSIDE,
};

enum class TieDotsPlacement {
enum class TieDotsPlacement : char {
AUTO,
BEFORE_DOTS,
AFTER_DOTS
Expand All @@ -1091,7 +1091,7 @@ enum class TieDotsPlacement {
// Key
//---------------------------------------------------------

enum class Key {
enum class Key : signed char {
C_B = -7,
G_B,
D_B,
Expand Down Expand Up @@ -1154,7 +1154,7 @@ struct SettingsCompat {
// recreates all.
//---------------------------------------------------------

enum class UpdateMode {
enum class UpdateMode : char {
DoNothing,
Update, // do screen refresh of RectF "refresh"
UpdateAll, // do complete screen refresh
Expand Down Expand Up @@ -1185,7 +1185,7 @@ struct std::hash<mu::engraving::InstrumentTrackId>
}
};

enum class ScoreStylePreset {
enum class ScoreStylePreset : char {
DEFAULT = 0,
MSN_16MM,
MSN_18MM,
Expand Down

0 comments on commit 16b2bec

Please sign in to comment.