Skip to content

Commit ab60bfd

Browse files
committed
Merge branch 'master' into muhammad/arch-64-fb-submit-master
* master: Bump [email protected] Remove duplicated attachWebsocketServer module Switch to ES6 Class Slider to ES6 Class Slider move prop comments to flow types Slider remove $FlowFixMe #take2 Revert D8234803: [RN] Slider remove $FlowFixMe normalizeColor to compute regexps lazily Implement release of FabricUIManager resources Add backward compatible support for onLayout event in Fabric refactor JSI module initialization Slider remove $FlowFixMe better place for dismiss all button Low the priority for logging events in fabric react-native-xcode.sh: Support Homebrew-installed nodenv make logMarker visible for consistency with logTaggedMarker
2 parents bab84fc + 30320f1 commit ab60bfd

33 files changed

+528
-473
lines changed

Libraries/Color/normalizeColor.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'use strict';
1313

1414
function normalizeColor(color: string | number): ?number {
15+
const matchers = getMatchers();
1516
let match;
1617

1718
if (typeof color === 'number') {
@@ -156,16 +157,23 @@ function call(...args) {
156157
return '\\(\\s*(' + args.join(')\\s*,\\s*(') + ')\\s*\\)';
157158
}
158159

159-
const matchers = {
160-
rgb: new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER)),
161-
rgba: new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER)),
162-
hsl: new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE)),
163-
hsla: new RegExp('hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER)),
164-
hex3: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
165-
hex4: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
166-
hex6: /^#([0-9a-fA-F]{6})$/,
167-
hex8: /^#([0-9a-fA-F]{8})$/,
168-
};
160+
let cachedMatchers;
161+
162+
function getMatchers() {
163+
if (cachedMatchers === undefined) {
164+
cachedMatchers = {
165+
rgb: new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER)),
166+
rgba: new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER)),
167+
hsl: new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE)),
168+
hsla: new RegExp('hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER)),
169+
hex3: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
170+
hex4: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
171+
hex6: /^#([0-9a-fA-F]{6})$/,
172+
hex8: /^#([0-9a-fA-F]{8})$/,
173+
};
174+
}
175+
return cachedMatchers;
176+
}
169177

170178
function parse255(str: string): number {
171179
const int = parseInt(str, 10);

0 commit comments

Comments
 (0)