Skip to content

Commit 41ec9ca

Browse files
authored
Merge pull request #1882 from joto/cleanup-int-double-buffer
Cleanup int double buffer
2 parents f9873fb + 6ff0321 commit 41ec9ca

File tree

5 files changed

+5
-50
lines changed

5 files changed

+5
-50
lines changed

src/db-copy-mgr.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,7 @@ class db_copy_mgr_t
290290
template <typename T>
291291
void add_value(T value)
292292
{
293-
m_current->buffer += std::to_string(value);
294-
}
295-
296-
void add_value(double value)
297-
{
298-
util::double_to_buffer tmp{value};
299-
m_current->buffer += tmp.c_str();
293+
m_current->buffer += fmt::to_string(value);
300294
}
301295

302296
void add_value(std::string const &s) { add_value(s.c_str()); }

src/osmtypes.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ class taglist_t
189189
}
190190

191191
/// Add tag to list without checking for duplicates
192-
void add_tag(char const *key, char const *value)
192+
template <typename T>
193+
void add_tag(char const *key, T&& value)
193194
{
194-
m_tags.emplace_back(key, value);
195+
m_tags.emplace_back(key, std::move(value));
195196
}
196197

197198
/// Add tag to list if there is no tag with that key yet

src/tagtransform-c.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ static void add_z_order(taglist_t *tags, bool *roads)
8484
z_order -= 100;
8585
}
8686

87-
util::integer_to_buffer z{z_order};
88-
tags->add_tag("z_order", z.c_str());
87+
tags->add_tag("z_order", fmt::to_string(z_order));
8988
}
9089

9190
c_tagtransform_t::c_tagtransform_t(options_t const *options, export_list exlist)

src/util.hpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,6 @@
2525

2626
namespace util {
2727

28-
class integer_to_buffer
29-
{
30-
// This is enough for 64 bit integers
31-
static constexpr std::size_t buffer_size = 21;
32-
33-
public:
34-
template <typename T>
35-
explicit integer_to_buffer(T value)
36-
{
37-
auto const result =
38-
fmt::format_to_n(m_buffer.begin(), buffer_size - 1, "{}", value);
39-
assert(result.size < buffer_size);
40-
*result.out = '\0';
41-
}
42-
43-
char const *c_str() const noexcept { return m_buffer.data(); }
44-
45-
private:
46-
std::array<char, buffer_size> m_buffer{};
47-
};
48-
4928
class double_to_buffer
5029
{
5130
static constexpr std::size_t buffer_size = 32;

tests/test-util.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@
1616
#include <string>
1717
#include <vector>
1818

19-
TEST_CASE("integer_to_buffer 1", "[NoDB]")
20-
{
21-
util::integer_to_buffer buffer{1};
22-
REQUIRE(std::strcmp(buffer.c_str(), "1") == 0);
23-
}
24-
25-
TEST_CASE("integer_to_buffer max", "[NoDB]")
26-
{
27-
util::integer_to_buffer buffer{std::numeric_limits<osmid_t>::max()};
28-
REQUIRE(std::strcmp(buffer.c_str(), "9223372036854775807") == 0);
29-
}
30-
31-
TEST_CASE("integer_to_buffer min", "[NoDB]")
32-
{
33-
util::integer_to_buffer buffer{std::numeric_limits<osmid_t>::min()};
34-
REQUIRE(std::strcmp(buffer.c_str(), "-9223372036854775808") == 0);
35-
}
36-
3719
TEST_CASE("double_to_buffer 0", "[NoDB]")
3820
{
3921
util::double_to_buffer buffer{0.0};

0 commit comments

Comments
 (0)