Skip to content

Object::isHero function is inefficient #1265

@xezon

Description

@xezon

Object::isHero function is slightly inefficient.

This contain lookup can be avoided by caching hero count status on heros entering/exiting the contain module.

void localIsHero( Object *obj, void* userData )
{
	Bool *hero = (Bool*)userData;
	
	if( obj && obj->isKindOf( KINDOF_HERO ) )
	{
		*hero = TRUE;
	}
}

Bool Object::isHero(void) const
{
	ContainModuleInterface *contain = getContain();
	if( contain )
	{
		Bool heroInside = FALSE;
		contain->iterateContained( localIsHero, (void*)(&heroInside), FALSE );
		if( heroInside )
		{
			return TRUE;
		}
	}
	return isKindOf( KINDOF_HERO );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    MinorSeverity: 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