[Perf] Add cache for emoji rendering
This commit is contained in:
parent
4d448e4d07
commit
7a324ec7ff
@ -1,12 +1,15 @@
|
|||||||
import React from '../../../lib/teact/teact';
|
import React from '../../../lib/teact/teact';
|
||||||
import EMOJI_REGEX, { removeVS16s } from '../../../lib/twemojiRegex';
|
import EMOJI_REGEX from '../../../lib/twemojiRegex';
|
||||||
|
|
||||||
import { TextPart } from '../../../types';
|
import { TextPart } from '../../../types';
|
||||||
|
|
||||||
import { RE_LINK_TEMPLATE, RE_MENTION_TEMPLATE } from '../../../config';
|
import { RE_LINK_TEMPLATE, RE_MENTION_TEMPLATE } from '../../../config';
|
||||||
import { IS_EMOJI_SUPPORTED } from '../../../util/environment';
|
import { IS_EMOJI_SUPPORTED } from '../../../util/environment';
|
||||||
import {
|
import {
|
||||||
fixNonStandardEmoji, handleEmojiLoad, LOADED_EMOJIS, nativeToUnified,
|
fixNonStandardEmoji,
|
||||||
|
handleEmojiLoad,
|
||||||
|
LOADED_EMOJIS,
|
||||||
|
nativeToUnifiedExtendedWithCache,
|
||||||
} from '../../../util/emoji';
|
} from '../../../util/emoji';
|
||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
import { compact } from '../../../util/iteratees';
|
import { compact } from '../../../util/iteratees';
|
||||||
@ -103,7 +106,7 @@ function replaceEmojis(textParts: TextPart[], size: 'big' | 'small', type: 'jsx'
|
|||||||
result.push(parts[0]);
|
result.push(parts[0]);
|
||||||
|
|
||||||
return emojis.reduce((emojiResult: TextPart[], emoji, i) => {
|
return emojis.reduce((emojiResult: TextPart[], emoji, i) => {
|
||||||
const code = nativeToUnified(removeVS16s(emoji));
|
const code = nativeToUnifiedExtendedWithCache(emoji);
|
||||||
if (!code) return emojiResult;
|
if (!code) return emojiResult;
|
||||||
const src = `./img-apple-${size === 'big' ? '160' : '64'}/${code}.png`;
|
const src = `./img-apple-${size === 'big' ? '160' : '64'}/${code}.png`;
|
||||||
const className = buildClassName(
|
const className = buildClassName(
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import EMOJI_REGEX from '../lib/twemojiRegex';
|
import EMOJI_REGEX, { removeVS16s } from '../lib/twemojiRegex';
|
||||||
|
import withCache from './withCache';
|
||||||
|
|
||||||
// Due to the fact that emoji from Apple do not contain some characters, it is necessary to remove them from emoji-data
|
// Due to the fact that emoji from Apple do not contain some characters, it is necessary to remove them from emoji-data
|
||||||
// https://github.com/iamcal/emoji-data/issues/136
|
// https://github.com/iamcal/emoji-data/issues/136
|
||||||
@ -72,6 +73,12 @@ export function nativeToUnified(emoji: string) {
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nativeToUnifiedExtended(emoji: string) {
|
||||||
|
return nativeToUnified(removeVS16s(emoji));
|
||||||
|
}
|
||||||
|
|
||||||
|
export const nativeToUnifiedExtendedWithCache = withCache(nativeToUnifiedExtended);
|
||||||
|
|
||||||
export function uncompressEmoji(data: EmojiRawData): EmojiData {
|
export function uncompressEmoji(data: EmojiRawData): EmojiData {
|
||||||
const emojiData: EmojiData = { categories: [], emojis: {} };
|
const emojiData: EmojiData = { categories: [], emojis: {} };
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user