Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve "is (not) one of (sensitive)" performance by only hashing value once #80

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/RolloutEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ export class RolloutEvaluator implements IRolloutEvaluator {
log += "no match";

break;
case 16: // is one of (sensitive)
case 16: { // is one of (sensitive)
const values: string[] = comparisonValue.split(",");
const hashedComparisonAttribute: string = sha1(comparisonAttribute);

for (let ci = 0; ci < values.length; ci++) {

if (values[ci].trim() === sha1(comparisonAttribute)) {
if (values[ci].trim() === hashedComparisonAttribute) {
log += "MATCH";
eLog.opAppendLine(log);

Expand All @@ -297,10 +298,13 @@ export class RolloutEvaluator implements IRolloutEvaluator {
log += "no match";

break;
}

case 17: { // is not one of (sensitive)
const hashedComparisonAttribute: string = sha1(comparisonAttribute);

case 17: // is not one of (sensitive)
if (!comparisonValue.split(",").some(e => {
if (e.trim() === sha1(comparisonAttribute)) {
if (e.trim() === hashedComparisonAttribute) {
return true;
}

Expand All @@ -315,6 +319,8 @@ export class RolloutEvaluator implements IRolloutEvaluator {
log += "no match";

break;
}

default:
break;
}
Expand Down