mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user