mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Drop the C shim for float formatting now that jsonpull is C++
json_print_one() reached fpfmt through dtoa_shortest(), a C-linkage
wrapper in text.cpp that strdup()ed the formatted string so the C
jsonpull could take it and free() it. jsonpull has been C++ since 4f26211,
so it can append the std::string directly and skip the copy, the
allocation, and the free.
That was the shim's only caller, so fpfmt/fpfmt.h goes away with it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wJRAuhMninQE4wK2TUfuZ
This commit is contained in:
+3
-1
@@ -9,7 +9,9 @@
|
|||||||
final digit (`9.823748927348929e+55` becomes `9.823748927348928e+55`). Every
|
final digit (`9.823748927348929e+55` becomes `9.823748927348928e+55`). Every
|
||||||
such value still parses back to exactly the same double, so this changes only
|
such value still parses back to exactly the same double, so this changes only
|
||||||
the spelling, never the number. `make fpfmt-bench` rebuilds the head-to-head
|
the spelling, never the number. `make fpfmt-bench` rebuilds the head-to-head
|
||||||
comparison against the old implementation.
|
comparison against the old implementation. `jsonpull`, now that it is C++,
|
||||||
|
calls `fpfmt::dtoa()` directly rather than through the `strdup`ing C shim
|
||||||
|
that `milo/milo.h` used to declare.
|
||||||
|
|
||||||
# 2.82.0
|
# 2.82.0
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
// C-callable shortest-float formatting, for jsonpull.
|
|
||||||
// The implementation lives in text.cpp and calls fpfmt::dtoa().
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// dtoa_shortest returns a newly strdup()ed shortest decimal form of val.
|
|
||||||
// The caller owns the result.
|
|
||||||
char *dtoa_shortest(double val);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "jsonpull.h"
|
#include "jsonpull.h"
|
||||||
#include "../fpfmt/fpfmt.h"
|
#include "../fpfmt/fpfmt.hpp"
|
||||||
|
|
||||||
#define BUFFER 10000
|
#define BUFFER 10000
|
||||||
|
|
||||||
@@ -803,9 +803,7 @@ static void json_print_one(std::string &val, const json_object *o) {
|
|||||||
snprintf(s, sizeof(s), "%llu", o->large_unsigned());
|
snprintf(s, sizeof(s), "%llu", o->large_unsigned());
|
||||||
val.append(s);
|
val.append(s);
|
||||||
} else {
|
} else {
|
||||||
char *s = dtoa_shortest(o->number());
|
val.append(fpfmt::dtoa(o->number()));
|
||||||
val.append(s);
|
|
||||||
free(s);
|
|
||||||
}
|
}
|
||||||
} else if (o->type == JSON_NULL) {
|
} else if (o->type == JSON_NULL) {
|
||||||
val.append("null");
|
val.append("null");
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "text.hpp"
|
#include "text.hpp"
|
||||||
#include "fpfmt/fpfmt.hpp"
|
#include "fpfmt/fpfmt.hpp"
|
||||||
#include "fpfmt/fpfmt.h"
|
|
||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -176,17 +175,6 @@ std::string format_commandline(int argc, char **argv) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for jsonpull to call from C
|
|
||||||
char *dtoa_shortest(double val) {
|
|
||||||
std::string s = fpfmt::dtoa(val);
|
|
||||||
char *dup = strdup(s.c_str());
|
|
||||||
if (dup == NULL) {
|
|
||||||
perror("strdup");
|
|
||||||
exit(EXIT_MEMORY);
|
|
||||||
}
|
|
||||||
return dup;
|
|
||||||
}
|
|
||||||
|
|
||||||
// to work with data from https://github.com/kmike/text-unidecode
|
// to work with data from https://github.com/kmike/text-unidecode
|
||||||
std::vector<std::string> read_unidecode(const char *fname) {
|
std::vector<std::string> read_unidecode(const char *fname) {
|
||||||
std::string data;
|
std::string data;
|
||||||
|
|||||||
Reference in New Issue
Block a user