Commit 9674aa96 authored by Volker Krause's avatar Volker Krause
Browse files

Split airport name index string data to stay below MSVC string length limit

This isn't really elegant, but it gets the job done for now.
parent cac6f5be
Pipeline #40251 failed with stage
in 1 minute and 51 seconds
......@@ -333,23 +333,34 @@ static constexpr Airport airport_table[] = {
out->write(R"(};
// reverse name lookup string table for unique strings
static const char name1_string_table[] =
static const char name1_string_table_0[] =
)");
// TODO suffix compression -> see KPublicTransport, that has generic code for this
std::vector<Name1Index> string_offsets;
string_offsets.reserve(m_labelMap.size());
uint32_t label_offset = 0;
uint32_t batch_size = 0;
for (auto it = m_labelMap.constBegin(); it != m_labelMap.constEnd(); ++it) {
if (it.value().size() > 1) {
continue;
}
const auto keySize = it.key().toUtf8().size();
if (batch_size + keySize > (1 << 16)) { // max string size on MSVC...
out->write(R"(;
static const char name1_string_table_1[] =
)");
batch_size = 0;
}
out->write(" \"");
out->write(it.key().toUtf8());
out->write("\" // ");
out->write(it.value().at(0).toUtf8());
out->write("\n");
string_offsets.emplace_back(Name1Index{label_offset, (uint8_t)it.key().toUtf8().size(), (uint16_t)std::distance(m_iataMap.begin(), m_iataMap.find(it.value().at(0)))});
label_offset += it.key().toUtf8().size();
string_offsets.emplace_back(Name1Index{label_offset, (uint8_t)keySize, (uint16_t)std::distance(m_iataMap.begin(), m_iataMap.find(it.value().at(0)))});
label_offset += keySize;
batch_size += keySize;
}
out->write(R"(;
......
......@@ -77,16 +77,25 @@ static void applyTransliterations(QStringList &fragments)
}
}
// HACK to work around MSVC string length limit
static const char* name1_string_table(uint32_t offset)
{
if (offset < sizeof(name1_string_table_0)) {
return name1_string_table_0 + offset;
}
return name1_string_table_1 + (offset - sizeof(name1_string_table_0));
}
static IataCode iataCodeForUniqueFragment(const QString &s)
{
const auto it = std::lower_bound(std::begin(name1_string_index), std::end(name1_string_index), s.toUtf8(), [](const Name1Index &lhs, const QByteArray &rhs) {
const auto cmp = strncmp(name1_string_table + lhs.offset(), rhs.constData(), std::min<int>(lhs.length, rhs.size()));
const auto cmp = strncmp(name1_string_table(lhs.offset()), rhs.constData(), std::min<int>(lhs.length, rhs.size()));
if (cmp == 0) {
return lhs.length < rhs.size();
}
return cmp < 0;
});
if (it == std::end(name1_string_index) || it->length != s.toUtf8().size() || strncmp(name1_string_table + it->offset(), s.toUtf8().constData(), it->length) != 0) {
if (it == std::end(name1_string_index) || it->length != s.toUtf8().size() || strncmp(name1_string_table(it->offset()), s.toUtf8().constData(), it->length) != 0) {
return {};
}
return airport_table[it->iataIndex].iataCode;
......
......@@ -7449,7 +7449,7 @@ static constexpr Airport airport_table[] = {
};
 
// reverse name lookup string table for unique strings
static const char name1_string_table[] =
static const char name1_string_table_0[] =
"aachen" // MST
"aalborg" // AAL
"aarhus" // AAR
......@@ -16589,6 +16589,8 @@ static const char name1_string_table[] =
"安康五里铺机场" // AKA
"安顺黄果树机场" // AVA
"宜宾五粮液机场" // YBP
;
static const char name1_string_table_1[] =
"宜昌三峡机场" // YIH
"宜春明月山机场" // YIC
"富蕴可可托海机场" // FYN
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