From 5d46fe787628bbb386ad1d6e3328696949ff331e Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 5 Jun 2018 15:16:12 -0700 Subject: [PATCH] Remove some unneeded explicit construction of strings --- geojson.cpp | 12 ++++++------ main.cpp | 14 +++++++------- plugin.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/geojson.cpp b/geojson.cpp index 7c46012..dff0e4b 100644 --- a/geojson.cpp +++ b/geojson.cpp @@ -66,7 +66,7 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom int t; for (t = 0; t < GEOM_TYPES; t++) { - if (geometry_type->string == std::string(geometry_names[t])) { + if (geometry_type->string == geometry_names[t]) { break; } } @@ -99,7 +99,7 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom json_object *ln = json_hash_get(tippecanoe, "layer"); if (ln != NULL && (ln->type == JSON_STRING || ln->type == JSON_NUMBER)) { - tippecanoe_layername = std::string(ln->string); + tippecanoe_layername = ln->string; } } @@ -221,7 +221,7 @@ void check_crs(json_object *j, const char *reading) { if (properties != NULL) { json_object *name = json_hash_get(properties, "name"); if (name->type == JSON_STRING) { - if (name->string != std::string(projection->alias)) { + if (name->string != projection->alias) { if (!quiet) { fprintf(stderr, "%s: Warning: GeoJSON specified projection \"%s\", not the expected \"%s\".\n", reading, name->string.c_str(), projection->alias); fprintf(stderr, "%s: If \"%s\" is not the expected projection, use -s to specify the right one.\n", reading, projection->alias); @@ -268,7 +268,7 @@ void parse_json(struct serialization_state *sst, json_pull *jp, int layer, std:: int i; int is_geometry = 0; for (i = 0; i < GEOM_TYPES; i++) { - if (type->string == std::string(geometry_names[i])) { + if (type->string == geometry_names[i]) { is_geometry = 1; break; } @@ -306,8 +306,8 @@ void parse_json(struct serialization_state *sst, json_pull *jp, int layer, std:: } } - if (type->string != std::string("Feature")) { - if (type->string == std::string("FeatureCollection")) { + if (type->string != "Feature") { + if (type->string == "FeatureCollection") { check_crs(j, sst->fname); json_free(j); } diff --git a/main.cpp b/main.cpp index 21d2f7a..7e5dce6 100644 --- a/main.cpp +++ b/main.cpp @@ -540,7 +540,7 @@ STREAM *streamfdopen(int fd, const char *mode, std::string const &fname) { s->fp = NULL; s->gz = NULL; - if (fname.size() > 3 && fname.substr(fname.size() - 3) == std::string(".gz")) { + if (fname.size() > 3 && fname.substr(fname.size() - 3) == ".gz") { s->gz = gzdopen(fd, mode); if (s->gz == NULL) { fprintf(stderr, "%s: %s: Decompression error\n", *av, fname.c_str()); @@ -1351,7 +1351,7 @@ int read_input(std::vector &sources, char *fname, int maxzoom, int minzo } size_t layer = a->second.id; - if (sources[source].file.size() > 7 && sources[source].file.substr(sources[source].file.size() - 7) == std::string(".geobuf")) { + if (sources[source].file.size() > 7 && sources[source].file.substr(sources[source].file.size() - 7) == ".geobuf") { struct stat st; if (fstat(fd, &st) != 0) { perror("fstat"); @@ -1422,7 +1422,7 @@ int read_input(std::vector &sources, char *fname, int maxzoom, int minzo continue; } - if (sources[source].file.size() > 4 && sources[source].file.substr(sources[source].file.size() - 4) == std::string(".csv")) { + if (sources[source].file.size() > 4 && sources[source].file.substr(sources[source].file.size() - 4) == ".csv") { std::atomic layer_seq[CPUS]; double dist_sums[CPUS]; size_t dist_counts[CPUS]; @@ -1478,7 +1478,7 @@ int read_input(std::vector &sources, char *fname, int maxzoom, int minzo int read_parallel_this = read_parallel ? '\n' : 0; - if (!(sources[source].file.size() > 3 && sources[source].file.substr(sources[source].file.size() - 3) == std::string(".gz"))) { + if (!(sources[source].file.size() > 3 && sources[source].file.substr(sources[source].file.size() - 3) == ".gz")) { if (fstat(fd, &st) == 0) { off = lseek(fd, 0, SEEK_CUR); if (off >= 0) { @@ -2394,16 +2394,16 @@ void parse_json_source(const char *arg, struct source &src) { exit(EXIT_FAILURE); } - src.file = std::string(fname->string); + src.file = fname->string; json_object *layer = json_hash_get(o, "layer"); if (layer != NULL && layer->type == JSON_STRING) { - src.layer = std::string(layer->string); + src.layer = layer->string; } json_object *description = json_hash_get(o, "description"); if (description != NULL && description->type == JSON_STRING) { - src.description = std::string(description->string); + src.description = description->string; } json_free(o); diff --git a/plugin.cpp b/plugin.cpp index a30f6c3..6401f20 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -113,7 +113,7 @@ std::vector parse_layers(int fd, int z, unsigned x, unsigned y, std:: if (type == NULL || type->type != JSON_STRING) { continue; } - if (type->string != std::string("Feature")) { + if (type->string != "Feature") { continue; } @@ -155,7 +155,7 @@ std::vector parse_layers(int fd, int z, unsigned x, unsigned y, std:: int t; for (t = 0; t < GEOM_TYPES; t++) { - if (geometry_type->string == std::string(geometry_names[t])) { + if (geometry_type->string == geometry_names[t]) { break; } } @@ -171,7 +171,7 @@ std::vector parse_layers(int fd, int z, unsigned x, unsigned y, std:: if (tippecanoe != NULL) { layer = json_hash_get(tippecanoe, "layer"); if (layer != NULL && layer->type == JSON_STRING) { - layername = std::string(layer->string); + layername = layer->string; } } @@ -318,7 +318,7 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: if (type == NULL || type->type != JSON_STRING) { continue; } - if (type->string != std::string("Feature")) { + if (type->string != "Feature") { continue; } @@ -360,7 +360,7 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: int t; for (t = 0; t < GEOM_TYPES; t++) { - if (geometry_type->string == std::string(geometry_names[t])) { + if (geometry_type->string == geometry_names[t]) { break; } } @@ -405,7 +405,7 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: if (tippecanoe != NULL) { json_object *layer = json_hash_get(tippecanoe, "layer"); if (layer != NULL && layer->type == JSON_STRING) { - layername = std::string(layer->string); + layername = layer->string; } json_object *index = json_hash_get(tippecanoe, "index");