1
0
Fork 0

Improve getFree*ActiveObjectId to reduce common case cpu usage drasticaly

mutilcraft-mt53
sapier 2013-04-21 15:54:29 +02:00 committed by kwolekr
parent 625a4c2e66
commit e9a4e98cb9
1 changed files with 14 additions and 12 deletions

View File

@ -1295,16 +1295,17 @@ bool isFreeServerActiveObjectId(u16 id,
u16 getFreeServerActiveObjectId( u16 getFreeServerActiveObjectId(
std::map<u16, ServerActiveObject*> &objects) std::map<u16, ServerActiveObject*> &objects)
{ {
u16 new_id = 1; //try to reuse id's as late as possible
static u16 last_used_id = 0;
u16 startid = last_used_id;
for(;;) for(;;)
{ {
if(isFreeServerActiveObjectId(new_id, objects)) last_used_id ++;
return new_id; if(isFreeServerActiveObjectId(last_used_id, objects))
return last_used_id;
if(new_id == 65535) if(last_used_id == startid)
return 0; return 0;
new_id++;
} }
} }
@ -2296,16 +2297,17 @@ bool isFreeClientActiveObjectId(u16 id,
u16 getFreeClientActiveObjectId( u16 getFreeClientActiveObjectId(
std::map<u16, ClientActiveObject*> &objects) std::map<u16, ClientActiveObject*> &objects)
{ {
u16 new_id = 1; //try to reuse id's as late as possible
static u16 last_used_id = 0;
u16 startid = last_used_id;
for(;;) for(;;)
{ {
if(isFreeClientActiveObjectId(new_id, objects)) last_used_id ++;
return new_id; if(isFreeClientActiveObjectId(last_used_id, objects))
return last_used_id;
if(new_id == 65535) if(last_used_id == startid)
return 0; return 0;
new_id++;
} }
} }