Optimize Integer bit operations fix (GH #1072)

This fix uses IntegerSecBlock directly. It avoids the potential second allocation during Grow at the expense of a potential slightly larger SecBlock
This commit is contained in:
Jeffrey Walton 2021-10-08 15:51:17 -04:00
parent 43e7c2c8c5
commit 5331e36173
No known key found for this signature in database
GPG Key ID: B36AB348921B1838

View File

@ -3809,20 +3809,22 @@ Integer Integer::And(const Integer& t) const
}
else if (reg.size() >= t.reg.size())
{
Integer result(t);
result.reg.Grow(t.reg.size());
AndWords(result.reg, reg, t.reg.size());
IntegerSecBlock temp(t.reg.size());
AndWords(temp, reg, t.reg, t.reg.size());
Integer result;
std::swap(result.reg, temp);
result.sign = POSITIVE;
return result;
}
else // reg.size() < t.reg.size()
{
Integer result(*this);
result.reg.Grow(reg.size());
AndWords(result.reg, t.reg, reg.size());
IntegerSecBlock temp(reg.size());
AndWords(temp, reg, t.reg, reg.size());
Integer result;
std::swap(result.reg, temp);
result.sign = POSITIVE;
return result;
}
}
@ -3841,20 +3843,22 @@ Integer Integer::Or(const Integer& t) const
}
else if (reg.size() >= t.reg.size())
{
Integer result(*this);
result.reg.Grow(t.reg.size());
OrWords(result.reg, t.reg, t.reg.size());
IntegerSecBlock temp(reg, reg.size());
OrWords(temp, t.reg, t.reg.size());
Integer result;
std::swap(result.reg, temp);
result.sign = POSITIVE;
return result;
}
else // reg.size() < t.reg.size()
{
Integer result(t);
result.reg.Grow(reg.size());
OrWords(result.reg, reg, reg.size());
IntegerSecBlock temp(t.reg, t.reg.size());
OrWords(temp, reg, reg.size());
Integer result;
std::swap(result.reg, temp);
result.sign = POSITIVE;
return result;
}
}
@ -3873,20 +3877,22 @@ Integer Integer::Xor(const Integer& t) const
}
else if (reg.size() >= t.reg.size())
{
Integer result(*this);
result.reg.Grow(t.reg.size());
XorWords(result.reg, t.reg, t.reg.size());
IntegerSecBlock temp(reg, reg.size());
XorWords(temp, t.reg, t.reg.size());
Integer result;
std::swap(result.reg, temp);
result.sign = POSITIVE;
return result;
}
else // reg.size() < t.reg.size()
{
Integer result(t);
result.reg.Grow(reg.size());
XorWords(result.reg, reg, reg.size());
IntegerSecBlock temp(t.reg, t.reg.size());
XorWords(temp, reg, reg.size());
Integer result;
std::swap(result.reg, temp);
result.sign = POSITIVE;
return result;
}
}