Skip to content

Commit

Permalink
perf: determine emoji support in reverse order (#160)
Browse files Browse the repository at this point in the history
* perf: determine emoji support in reverse order

* fix: tweak code comment

* fix: tweak code comment

* refactor: refactor code a bit
  • Loading branch information
nolanlawson committed Jul 2, 2021
1 parent 24b3ee1 commit 2603055
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
18 changes: 9 additions & 9 deletions bin/versionsAndTestEmoji.js
Expand Up @@ -8,14 +8,14 @@
// "face without mouth" plus "fog".) These emoji can only be filtered using the width test,
// which happens in checkZwjSupport.js.
export const versionsAndTestEmoji = {
'πŸ˜ƒ': 0.6,
'😐️': 0.7,
'πŸ˜€': 1,
'πŸ‘οΈβ€πŸ—¨οΈ': 2,
'🀣': 3,
'πŸ‘±β€β™€οΈ': 4,
'🀩': 5,
'πŸ₯°': 11, // smiling face with hearts
'πŸ₯²': 13.1, // smiling face with tear, technically from v13 but see note above
'πŸ₯»': 12.1, // sari, technically from v12 but see note above
'πŸ₯²': 13.1 // smiling face with tear, technically from v13 but see note above
'πŸ₯°': 11,
'🀩': 5,
'πŸ‘±β€β™€οΈ': 4,
'🀣': 3,
'πŸ‘οΈβ€πŸ—¨οΈ': 2,
'πŸ˜€': 1,
'😐️': 0.7,
'πŸ˜ƒ': 0.6
}
12 changes: 7 additions & 5 deletions src/picker/utils/determineEmojiSupportLevel.js
Expand Up @@ -6,18 +6,20 @@ import { testColorEmojiSupported } from './testColorEmojiSupported'
/* istanbul ignore next */
export function determineEmojiSupportLevel () {
performance.mark('determineEmojiSupportLevel')
const entries = Object.entries(versionsAndTestEmoji)
try {
let res
for (const [emoji, version] of Object.entries(versionsAndTestEmoji)) {
// start with latest emoji and work backwards
for (const [emoji, version] of entries) {
if (testColorEmojiSupported(emoji)) {
res = version
return version
}
}
return res
} catch (e) { // canvas error
console.log('Ignoring canvas error', e)
return Math.max(...Object.values(versionsAndTestEmoji))
} finally {
performance.measure('determineEmojiSupportLevel', 'determineEmojiSupportLevel')
}
// In case of an error, be generous and just assume all emoji are supported (e.g. for canvas errors
// due to anti-fingerprinting add-ons). Better to show some gray boxes than nothing at all.
return entries[0][1] // first one in the list is the most recent version
}

0 comments on commit 2603055

Please sign in to comment.