mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 13:12:46 +00:00 
			
		
		
		
	LibDraw: Store emojis in a HashMap<u32, RefPtr<GraphicsBitmap>>
Get rid of the dedicated Emoji class to make it easier to store a null value signifying a failed lookup. This allows us to remember failed lookups, making subsequent failures for the same codepoint much faster. :^)
This commit is contained in:
		
							parent
							
								
									b3a63e1d50
								
							
						
					
					
						commit
						0d8aaaaa44
					
				
					 5 changed files with 19 additions and 29 deletions
				
			
		|  | @ -3,25 +3,22 @@ | |||
| #include <LibDraw/Emoji.h> | ||||
| #include <LibDraw/GraphicsBitmap.h> | ||||
| 
 | ||||
| static HashMap<u32, Emoji> s_emojis; | ||||
| static HashMap<u32, RefPtr<GraphicsBitmap>> s_emojis; | ||||
| 
 | ||||
| Emoji::Emoji(NonnullRefPtr<GraphicsBitmap> bitmap) | ||||
|     : m_bitmap(move(bitmap)) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| const Emoji* Emoji::emoji_for_codepoint(u32 codepoint) | ||||
| const GraphicsBitmap* Emoji::emoji_for_codepoint(u32 codepoint) | ||||
| { | ||||
|     auto it = s_emojis.find(codepoint); | ||||
|     if (it != s_emojis.end()) | ||||
|         return &(*it).value; | ||||
|         return (*it).value.ptr(); | ||||
| 
 | ||||
|     String path = String::format("/res/emoji/U+%X.png", codepoint); | ||||
| 
 | ||||
|     auto bitmap = GraphicsBitmap::load_from_file(path); | ||||
|     if (!bitmap) | ||||
|     if (!bitmap) { | ||||
|         s_emojis.set(codepoint, nullptr); | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     s_emojis.set(codepoint, Emoji { bitmap.release_nonnull() }); | ||||
|     return &(*s_emojis.find(codepoint)).value; | ||||
|     s_emojis.set(codepoint, bitmap); | ||||
|     return bitmap.ptr(); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling