From b29a51b4d4e096376e01665c0e2d132fcd538b6e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 19 Sep 2009 23:59:02 +0000 Subject: [PATCH] Avoid some temporary strings. llvm-svn: 82339 --- lib/Support/CommandLine.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index d3524a9e580..445fcc78862 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -26,6 +26,7 @@ #include "llvm/System/Path.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/config.h" #include @@ -894,11 +895,7 @@ bool parser::parse(Option &O, const char *ArgName, // bool parser::parse(Option &O, const char *ArgName, StringRef Arg, int &Value) { - char *End; - // FIXME: Temporary. - std::string TMP = Arg.str(); - Value = (int)strtol(TMP.c_str(), &End, 0); - if (*End != 0) + if (Arg.getAsInteger(0, Value)) return O.error("'" + Arg + "' value invalid for integer argument!"); return false; } @@ -907,16 +904,8 @@ bool parser::parse(Option &O, const char *ArgName, // bool parser::parse(Option &O, const char *ArgName, StringRef Arg, unsigned &Value) { - char *End; - errno = 0; - - // FIXME: Temporary. - std::string TMP = Arg.str(); - unsigned long V = strtoul(TMP.c_str(), &End, 0); - Value = (unsigned)V; - if (((V == ULONG_MAX) && (errno == ERANGE)) - || (*End != 0) - || (Value != V)) + + if (Arg.getAsInteger(0, Value)) return O.error("'" + Arg + "' value invalid for uint argument!"); return false; } @@ -924,10 +913,8 @@ bool parser::parse(Option &O, const char *ArgName, // parser/parser implementation // static bool parseDouble(Option &O, StringRef Arg, double &Value) { - // FIXME: Temporary. - std::string TMP = Arg.str(); - - const char *ArgStart = TMP.c_str(); + SmallString<32> TmpStr(Arg.begin(), Arg.end()); + const char *ArgStart = TmpStr.c_str(); char *End; Value = strtod(ArgStart, &End); if (*End != 0)