Optimise encodePolyline function (#6940)
This commit is contained in:
committed by
GitHub
parent
3d01d96036
commit
7d72dfebf7
@@ -10,9 +10,19 @@
|
||||
namespace osrm::engine::detail // anonymous to keep TU local
|
||||
{
|
||||
|
||||
std::string encode(int number_to_encode)
|
||||
void encode(int number_to_encode, std::string &output)
|
||||
{
|
||||
std::string output;
|
||||
if (number_to_encode < 0)
|
||||
{
|
||||
const unsigned binary = std::llabs(number_to_encode);
|
||||
const unsigned twos = (~binary) + 1u;
|
||||
const unsigned shl = twos << 1u;
|
||||
number_to_encode = static_cast<int>(~shl);
|
||||
}
|
||||
else
|
||||
{
|
||||
number_to_encode <<= 1u;
|
||||
}
|
||||
while (number_to_encode >= 0x20)
|
||||
{
|
||||
const int next_value = (0x20 | (number_to_encode & 0x1f)) + 63;
|
||||
@@ -22,31 +32,6 @@ std::string encode(int number_to_encode)
|
||||
|
||||
number_to_encode += 63;
|
||||
output += static_cast<char>(number_to_encode);
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string encode(std::vector<int> &numbers)
|
||||
{
|
||||
std::string output;
|
||||
for (auto &number : numbers)
|
||||
{
|
||||
if (number < 0)
|
||||
{
|
||||
const unsigned binary = std::llabs(number);
|
||||
const unsigned twos = (~binary) + 1u;
|
||||
const unsigned shl = twos << 1u;
|
||||
number = static_cast<int>(~shl);
|
||||
}
|
||||
else
|
||||
{
|
||||
number <<= 1u;
|
||||
}
|
||||
}
|
||||
for (const int number : numbers)
|
||||
{
|
||||
output += encode(number);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// https://developers.google.com/maps/documentation/utilities/polylinealgorithm
|
||||
|
||||
Reference in New Issue
Block a user