Commit 7f721452 authored by Matthieu Martin's avatar Matthieu Martin Committed by Facebook Github Bot

Request context: optimize exec_set_difference

Summary: This code is hot enough that this might matter. Though likely over-optimization.

Reviewed By: djwatson

Differential Revision: D9197636

fbshipit-source-id: d9e2a90410c03a73d1754d99c72967f5dcd96c0f
parent 6c822a8a
......@@ -166,13 +166,19 @@ void exec_set_difference(const TData& data, const TData& other, TExec&& exec) {
auto oiter = other.begin();
auto oend = other.end();
while (diter != dend) {
if (oiter == oend || *diter < *oiter) {
// Order of "if" optimizes for the 2 common cases:
// 1) empty other, switching to default context
// 2) identical other, switching to similar context with same callbacks
if (oiter == oend) {
exec(*diter);
++diter;
} else if (*oiter < *diter) {
} else if (*diter == *oiter) {
++diter;
++oiter;
} else {
} else if (*diter < *oiter) {
exec(*diter);
++diter;
} else {
++oiter;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment