Honorable Member Mali 42406 Posted October 15, 2023 Honorable Member Share Posted October 15, 2023 #Solution 1: This is the hidden content, please Sign In or Sign Up #Solution 2: This is the hidden content, please Sign In or Sign Up 285 2 53 10 102 Link to comment Share on other sites More sharing options...
Chookez 73 Posted October 16, 2023 Share Posted October 16, 2023 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. 1 1 Link to comment Share on other sites More sharing options...
Honorable Member Mali 42406 Posted October 16, 2023 Author Honorable Member Share Posted October 16, 2023 (edited) 1 hour ago, 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. So your optimized code is auto and emplace? Can you explain what you optimized exactly? Edit: If your optimize is using modern c++ functions like emplace, I don't use this on purpose. Spoiler Edited October 16, 2023 by Mali 1 1 1 Link to comment Share on other sites More sharing options...
Honorable Member xP3NG3Rx 19763 Posted October 16, 2023 Honorable Member Share Posted October 16, 2023 (edited) Don't argue with experienced ones, they will win. Anyway, anyone who is using modern c++ on their source has the brain to convert anything they want to adapt to their code without even mention it. Edited October 16, 2023 by Metin2 Dev International Core X - External 2 Internal 1 3 2 Link to comment Share on other sites More sharing options...
Honorable Member Mali 42406 Posted October 16, 2023 Author Honorable Member Share Posted October 16, 2023 6 minutes ago, xP3NG3Rx said: Don't argue with experienced ones, they will win. Anyway, anyone who is using modern c++ on their source has the brain to convert anything they want to adapt to their code without even mention it. I used to use modern C++ on my systems back then, but then I saw some people complaining about it (compiler problems, etc.). Later, I started not even using auto in order to alleviate these complaints and to maintain code integrity with Metin2's old source codes. Like you said "anyone who is using modern c++ on their source has the brain to convert anything they want to adapt to their code without even mention it." Link to comment Share on other sites More sharing options...
Premium WeedHex 636 Posted October 16, 2023 Premium Share Posted October 16, 2023 Are you having an asshole contest? You can also make constant the iterator Joking apart, very thanks Mali! 1 1 Link to comment Share on other sites More sharing options...
Active+ Member blaxis 283 Posted October 16, 2023 Active+ Member Share Posted October 16, 2023 thank you for sharing. There are many memory problems in Metin2 that are waiting to be fixed and cause unnecessary CPU increase. Do you have a post about these? 1 Link to comment Share on other sites More sharing options...
Honorable Member Mali 42406 Posted October 17, 2023 Author Honorable Member Share Posted October 17, 2023 10 hours ago, blaxis said: thank you for sharing. There are many memory problems in Metin2 that are waiting to be fixed and cause unnecessary CPU increase. Do you have a post about these? They are not easy to find. Think it's been 10 years since the source codes were leaked, we even just found this I share what I found 2 4 Link to comment Share on other sites More sharing options...
Active+ Member HFWhite 529 Posted October 17, 2023 Active+ Member Share Posted October 17, 2023 which one should we use? Link to comment Share on other sites More sharing options...
Premium WeedHex 636 Posted October 17, 2023 Premium Share Posted October 17, 2023 10 hours ago, SCOOB said: which one should we use? Is the same, just avoid CWhisper::New() without checking. Link to comment Share on other sites More sharing options...
ReDraco 3 Posted October 18, 2023 Share Posted October 18, 2023 Oh tanks 2 Link to comment Share on other sites More sharing options...
Dēcapitāre 1 Posted October 21, 2023 Share Posted October 21, 2023 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 1 1 Link to comment Share on other sites More sharing options...
Active Member Koray 2014 Posted October 21, 2023 Active Member Share Posted October 21, 2023 #MoreOptimization CWhisper* CPythonChat::CreateWhisper(const char* c_szName) { auto& whisper = m_WhisperMap[c_szName]; if (!whisper) whisper = CWhisper::New(); return whisper; } 3 1 1 Link to comment Share on other sites More sharing options...
ReDraco 3 Posted October 23, 2023 Share Posted October 23, 2023 It seems like you are having fun using ChatGPT, but without using your brain. 1 1 1 1 3 Link to comment Share on other sites More sharing options...
Recommended Posts