From 411527a240bfed9439f94fbfdccf382beeb80151 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Jan 2014 22:52:12 +0100 Subject: db/upnp: don't use stringToTokens() in ParseDuration() Reduce bloat. --- src/db/upnp/Directory.cxx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx index ce0a86fda..2fa69e4bb 100644 --- a/src/db/upnp/Directory.cxx +++ b/src/db/upnp/Directory.cxx @@ -24,6 +24,7 @@ #include "Tags.hxx" #include "tag/TagBuilder.hxx" #include "tag/TagTable.hxx" +#include "util/NumberParser.hxx" #include #include @@ -45,12 +46,27 @@ ParseItemClass(const char *name) gcc_pure static int -ParseDuration(const std::string &duration) +ParseDuration(const char *duration) { - const auto v = stringToTokens(duration, ":"); - if (v.size() != 3) + char *endptr; + + unsigned result = ParseUnsigned(duration, &endptr); + if (endptr == duration || *endptr != ':') + return 0; + + result *= 60; + duration = endptr + 1; + result += ParseUnsigned(duration, &endptr); + if (endptr == duration || *endptr != ':') return 0; - return atoi(v[0].c_str())*3600 + atoi(v[1].c_str())*60 + atoi(v[2].c_str()); + + result *= 60; + duration = endptr + 1; + result += ParseUnsigned(duration, &endptr); + if (endptr == duration || *endptr != 0) + return 0; + + return result; } /** -- cgit v1.2.3