Skip to content

GameMessage::getCommandTypeAsAsciiString looks inefficient #838

Open
@xezon

Description

@xezon
  1. Allocates a new string on every call.
  2. Uses if condition instead of switch case. Unclear if the compiler will make it nice.
AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
{
#define CHECK_IF(x) if (t == x) { return #x; }
	AsciiString commandName = "UnknownMessage";
	if (t >= GameMessage::MSG_COUNT)
	{
		commandName = "Invalid command";
	}
	CHECK_IF(MSG_INVALID)
	CHECK_IF(MSG_FRAME_TICK)
	CHECK_IF(MSG_RAW_MOUSE_BEGIN)
	CHECK_IF(MSG_RAW_MOUSE_POSITION)
	CHECK_IF(MSG_RAW_MOUSE_LEFT_BUTTON_DOWN)
	CHECK_IF(MSG_RAW_MOUSE_LEFT_DOUBLE_CLICK)
	CHECK_IF(MSG_RAW_MOUSE_LEFT_BUTTON_UP)
	CHECK_IF(MSG_RAW_MOUSE_LEFT_CLICK)
	CHECK_IF(MSG_RAW_MOUSE_LEFT_DRAG)
...
// hundreds more

Metadata

Metadata

Assignees

Labels

InvestigateMinorSeverity: Minor < Major < Critical < BlockerPerformanceIs a performance concern

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions