Skip to content

Commit

Permalink
Avoid an int->string->int conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Jan 24, 2024
1 parent 16560f8 commit b91908c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int

if (layer.keys[feature.tags[i]] == "tippecanoe:retain_points_multiplier_sequence") {
mvt_value v = layer.values[feature.tags[i + 1]];
feature.seq = atoll(mvt_value_to_serial_val(v).s.c_str());
feature.seq = mvt_value_to_long_long(v);
feature.tags.erase(feature.tags.begin() + i, feature.tags.begin() + i + 2);
}
}
Expand Down
25 changes: 25 additions & 0 deletions mvt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,3 +800,28 @@ serial_val mvt_value_to_serial_val(mvt_value const &v) {

return sv;
}

// This extracts an integer value from an mvt_value
long long mvt_value_to_long_long(mvt_value const &v) {
switch (v.type) {
case mvt_string:
return atoll(v.string_value.c_str());
case mvt_float:
return v.numeric_value.float_value;
case mvt_double:
return v.numeric_value.double_value;
case mvt_int:
return v.numeric_value.int_value;
case mvt_uint:
return v.numeric_value.uint_value;
case mvt_sint:
return v.numeric_value.sint_value;
case mvt_bool:
return v.numeric_value.bool_value;
case mvt_null:
return 0;
default:
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
}
1 change: 1 addition & 0 deletions mvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ int compress(std::string const &input, std::string &output, bool gz);
int dezig(unsigned n);

mvt_value stringified_to_mvt_value(int type, const char *s);
long long mvt_value_to_long_long(mvt_value const &v);

bool is_integer(const char *s, long long *v);
bool is_unsigned_integer(const char *s, unsigned long long *v);
Expand Down

0 comments on commit b91908c

Please sign in to comment.