Jump to content

Dēcapitāre

Member
  • Posts

    1
  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by Dēcapitāre

  1. On 10/16/2023 at 6:02 PM, Chookez said:

    A slightly more optimized code for the second solution.

    CWhisper* CPythonChat::CreateWhisper(const char* c_szName)
    {
    	auto itor = m_WhisperMap.find(c_szName);
    
    	CWhisper* pWhisper;
    
    	if (itor == m_WhisperMap.end())
    	{
    		pWhisper = CWhisper::New();
    		m_WhisperMap.emplace(c_szName, pWhisper);
    	}
    	else
    	{
    		pWhisper = itor->second;
    	}
    
    	return pWhisper;
    }

    I'm sorry to bother you.

     

    I would consider this to be a "optimization":

     

    CWhisper* CPythonChat::CreateWhisper(const char* c_szName)
    {
    	auto [itor, inserted] = m_WhisperMap.try_emplace(c_szName, nullptr);
    	if (inserted)
    	{
    		itor->second = CWhisper::New();
    	}
    	return itor->second;
    }


    Best regards

    • Metin2 Dev 1
    • Sad 1
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.