Feeds:
文章
留言

Archive for 八月 17th, 2007

最近再研究 WinVNC Source Code,看到下面這段有點怪的程式碼

BOOL
vncServer::RemoteEventReceived()
{
 vncClientList::iterator i;
 BOOL result = FALSE;
 omni_mutex_lock l(m_clientsLock);

 // Iterate over the authorised clients
 for (i = m_authClients.begin(); i != m_authClients.end(); i++)
 {
  result = result || GetClient(*i)->RemoteEventReceived();
 }
 return result;
}

其中 GetClient(*i)->RemoteEventReceived() 回傳 BOOL。這段 Code 的意思應該是找到第一個執行 RemoteEventReceived() 回傳 TRUE,之後就不要再執行 RemoteEventReceived(),如果是這樣,為什麼不寫成

BOOL
vncServer::RemoteEventReceived()
{
 vncClientList::iterator i;
 BOOL result = FALSE;
 omni_mutex_lock l(m_clientsLock);

 // Iterate over the authorised clients
 for (i = m_authClients.begin(); i != m_authClients.end(); i++)
 {
  if (GetClient(*i)->RemoteEventReceived()){
    result = TRUE;
    break;    
  }

 }
 return result;
}

如此,不是可以避免不必要的迭代和 assign 動作嗎?

Read Full Post »

20070817

Read Full Post »