From 5e87cfed5aa060768185d7a2800b4c746a6ffa49 Mon Sep 17 00:00:00 2001 From: artemp Date: Mon, 10 Feb 2014 12:18:52 +0000 Subject: [PATCH] c++ - prefer switch over long-ish if/else (be nice to compiler) --- src/style/value.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/style/value.cpp b/src/style/value.cpp index 8da66966f..99086f377 100644 --- a/src/style/value.cpp +++ b/src/style/value.cpp @@ -1,25 +1,28 @@ #include llmr::Value llmr::parseValue(pbf data) { - while (data.next()) { - if (data.tag == 1) { // string_value + while (data.next()) + { + switch (data.tag) + { + case 1: // string_value return data.string(); - } else if (data.tag == 2) { // float_value + case 2: // float_value return data.float32(); - } else if (data.tag == 3) { // double_value + case 3: // double_value return data.float64(); - } else if (data.tag == 4) { // int_value + case 4: // int_value return data.varint(); - } else if (data.tag == 5) { // uint_value + case 5: // uint_value return data.varint(); - } else if (data.tag == 6) { // sint_value + case 6: // sint_value return data.svarint(); - } else if (data.tag == 7) { // bool_value + case 7: // bool_value return data.boolean(); - } else { + default: data.skip(); + break; } } - return false; }