GameMonkey Script

GameMonkey Script Forums
It is currently Mon Mar 18, 2019 7:24 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Nov 07, 2007 12:24 pm 
Offline

Joined: Fri Nov 24, 2006 9:50 am
Posts: 165
Changing the string compares to check their ref pointers gives a substantial speed up to code that does a lot of string operations and comparing.

gmOperators.cpp:
Code:
void GM_CDECL gmStringOpEQ(gmThread * a_thread, gmVariable * a_operands)
{
  gmMachine * machine = a_thread->GetMachine();
  if ( a_operands[0].m_type == GM_STRING && a_operands[1].m_type == GM_STRING )
  {
     a_operands->m_type = GM_INT;
     a_operands->m_value.m_ref = a_operands[0].m_value.m_ref == a_operands[1].m_value.m_ref;
     return;
  }
  char buffer1[GMSTRING_BUFFERSIZE];
  char buffer2[GMSTRING_BUFFERSIZE];
  const char * str1 = gmUnknownToString(machine, a_operands, buffer1);
  const char * str2 = gmUnknownToString(machine, a_operands + 1, buffer2);
  int res = strcmp(str1, str2);
  a_operands->m_type = GM_INT;
  a_operands->m_value.m_ref = (res == 0) ? 1 : 0;
}
void GM_CDECL gmStringOpNEQ(gmThread * a_thread, gmVariable * a_operands)
{
  gmMachine * machine = a_thread->GetMachine();
  if ( a_operands[0].m_type == GM_STRING && a_operands[1].m_type == GM_STRING )
  {
     a_operands->m_type = GM_INT;
     a_operands->m_value.m_ref = a_operands[0].m_value.m_ref != a_operands[1].m_value.m_ref;
     return;
  }
 
  char buffer1[GMSTRING_BUFFERSIZE];
  char buffer2[GMSTRING_BUFFERSIZE];
  const char * str1 = gmUnknownToString(machine, a_operands, buffer1);
  const char * str2 = gmUnknownToString(machine, a_operands + 1, buffer2);
  int res = strcmp(str1, str2);
  a_operands->m_type = GM_INT;
  a_operands->m_value.m_ref = (res == 0) ? 0 : 1;
}


This optimisation should probably should go in the main source.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group