mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1391405: Part 3b - Speed up schema normalization for choices types some more. r=zombie
Like part a, but for `choices` messages rather than error messages. MozReview-Commit-ID: 7dJ0NL2fUh5 --HG-- extra : rebase_source : 477f1364c0904bde78d54eae083bdb8e49ee5732 extra : histedit_source : 38c336b3a59481b6f2523798367159fb757c6485
This commit is contained in:
parent
7325526f5a
commit
cbddab6266
@ -406,7 +406,7 @@ class Context {
|
||||
* only possible matching schema. If a function is passed, it
|
||||
* will be evaluated when the error string is first needed, and
|
||||
* must return a string.
|
||||
* @param {string} choicesMessage
|
||||
* @param {string|function} choicesMessage
|
||||
* The message describing the valid what constitutes a valid
|
||||
* value for this schema, which will be displayed when multiple
|
||||
* schema choices are available and none match.
|
||||
@ -496,19 +496,23 @@ class Context {
|
||||
try {
|
||||
let result = callback();
|
||||
|
||||
return {result, choices: Array.from(choices)};
|
||||
return {result, choices};
|
||||
} finally {
|
||||
this.currentChoices = currentChoices;
|
||||
this.choicePathIndex = choicePathIndex;
|
||||
|
||||
choices = Array.from(choices);
|
||||
if (choices.length == 1) {
|
||||
currentChoices.add(choices[0]);
|
||||
} else if (choices.length) {
|
||||
let n = choices.length - 1;
|
||||
choices[n] = `or ${choices[n]}`;
|
||||
if (choices.size == 1) {
|
||||
for (let choice of choices) {
|
||||
currentChoices.add(choice);
|
||||
}
|
||||
} else if (choices.size) {
|
||||
this.error(null, () => {
|
||||
let array = Array.from(choices, forceString);
|
||||
let n = array.length - 1;
|
||||
array[n] = `or ${array[n]}`;
|
||||
|
||||
this.error(null, `must either [${choices.join(", ")}]`);
|
||||
return `must either [${array.join(", ")}]`;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1248,10 +1252,11 @@ class ChoiceType extends Type {
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
if (choices.length <= 1) {
|
||||
if (choices.size <= 1) {
|
||||
return error;
|
||||
}
|
||||
|
||||
choices = Array.from(choices, forceString);
|
||||
let n = choices.length - 1;
|
||||
choices[n] = `or ${choices[n]}`;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user