perf: avoid redundant map lookup in NativeImage::GetHICON() (#39082)

perf: avoid double map lookup in NativeImage::GetHICON()

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot]
2023-07-13 10:25:01 +02:00
committed by GitHub
parent e7928ce519
commit db581a204d

View File

@@ -202,21 +202,23 @@ bool NativeImage::TryConvertNativeImage(v8::Isolate* isolate,
#if BUILDFLAG(IS_WIN)
HICON NativeImage::GetHICON(int size) {
auto iter = hicons_.find(size);
if (iter != hicons_.end())
if (auto iter = hicons_.find(size); iter != hicons_.end())
return iter->second.get();
// First try loading the icon with specified size.
if (!hicon_path_.empty()) {
hicons_[size] = ReadICOFromPath(size, hicon_path_);
return hicons_[size].get();
auto& hicon = hicons_[size];
hicon = ReadICOFromPath(size, hicon_path_);
return hicon.get();
}
// Then convert the image to ICO.
if (image_.IsEmpty())
return NULL;
hicons_[size] = IconUtil::CreateHICONFromSkBitmap(image_.AsBitmap());
return hicons_[size].get();
auto& hicon = hicons_[size];
hicon = IconUtil::CreateHICONFromSkBitmap(image_.AsBitmap());
return hicon.get();
}
#endif