From cebf5bc2ee0c5fdfa2b604e002b60add3cc895f0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 30 Mar 2010 05:34:02 +0000 Subject: [PATCH] stringref'ize Timer apis git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99877 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Timer.h | 18 +++++++++--------- lib/Support/Timer.cpp | 31 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/include/llvm/Support/Timer.h b/include/llvm/Support/Timer.h index c5b921c7485..00dfeaa4fad 100644 --- a/include/llvm/Support/Timer.h +++ b/include/llvm/Support/Timer.h @@ -16,6 +16,7 @@ #define LLVM_SUPPORT_TIMER_H #include "llvm/System/DataTypes.h" +#include "llvm/ADT/StringRef.h" #include #include #include @@ -88,8 +89,8 @@ class Timer { Timer **Prev, *Next; // Doubly linked list of timers in the group. public: - explicit Timer(const std::string &N) : TG(0) { init(N); } - Timer(const std::string &N, TimerGroup &tg) : TG(0) { init(N, tg); } + explicit Timer(StringRef N) : TG(0) { init(N); } + Timer(StringRef N, TimerGroup &tg) : TG(0) { init(N, tg); } Timer(const Timer &RHS) : TG(0) { assert(RHS.TG == 0 && "Can only copy uninitialized timers"); } @@ -101,8 +102,8 @@ public: // Create an uninitialized timer, client must use 'init'. explicit Timer() : TG(0) {} - void init(const std::string &N); - void init(const std::string &N, TimerGroup &tg); + void init(StringRef N); + void init(StringRef N, TimerGroup &tg); const std::string &getName() const { return Name; } bool isInitialized() const { return TG != 0; } @@ -149,9 +150,8 @@ public: /// is primarily used for debugging and for hunting performance problems. /// struct NamedRegionTimer : public TimeRegion { - explicit NamedRegionTimer(const std::string &Name); - explicit NamedRegionTimer(const std::string &Name, - const std::string &GroupName); + explicit NamedRegionTimer(StringRef Name); + explicit NamedRegionTimer(StringRef Name, StringRef GroupName); }; @@ -169,10 +169,10 @@ class TimerGroup { TimerGroup(const TimerGroup &TG); // DO NOT IMPLEMENT void operator=(const TimerGroup &TG); // DO NOT IMPLEMENT public: - explicit TimerGroup(const std::string &name); + explicit TimerGroup(StringRef name); ~TimerGroup(); - void setName(const std::string &name) { Name = name; } + void setName(StringRef name) { Name.assign(name.begin(), name.end()); } /// print - Print any started timers in this group and zero them. void print(raw_ostream &OS); diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index 5b17a26b839..4fac0737f0c 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -55,20 +55,20 @@ namespace { // CreateInfoOutputFile - Return a file stream to print our output on. raw_ostream *llvm::CreateInfoOutputFile() { - std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename(); - if (LibSupportInfoOutputFilename.empty()) + const std::string &OutputFilename = getLibSupportInfoOutputFilename(); + if (OutputFilename.empty()) return new raw_fd_ostream(2, false); // stderr. - if (LibSupportInfoOutputFilename == "-") + if (OutputFilename == "-") return new raw_fd_ostream(1, false); // stdout. std::string Error; - raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(), + raw_ostream *Result = new raw_fd_ostream(OutputFilename.c_str(), Error, raw_fd_ostream::F_Append); if (Error.empty()) return Result; errs() << "Error opening info-output-file '" - << LibSupportInfoOutputFilename << " for appending!\n"; + << OutputFilename << " for appending!\n"; delete Result; return new raw_fd_ostream(2, false); // stderr. } @@ -96,17 +96,17 @@ static TimerGroup *getDefaultTimerGroup() { // Timer Implementation //===----------------------------------------------------------------------===// -void Timer::init(const std::string &N) { +void Timer::init(StringRef N) { assert(TG == 0 && "Timer already initialized"); - Name = N; + Name.assign(N.begin(), N.end()); Started = false; TG = getDefaultTimerGroup(); TG->addTimer(*this); } -void Timer::init(const std::string &N, TimerGroup &tg) { +void Timer::init(StringRef N, TimerGroup &tg) { assert(TG == 0 && "Timer already initialized"); - Name = N; + Name.assign(N.begin(), N.end()); Started = false; TG = &tg; TG->addTimer(*this); @@ -201,7 +201,7 @@ public: delete I->second.first; } - Timer &get(const std::string &Name, const std::string &GroupName) { + Timer &get(StringRef Name, StringRef GroupName) { sys::SmartScopedLock L(*TimerLock); std::pair &GroupEntry = Map[GroupName]; @@ -219,7 +219,7 @@ public: static ManagedStatic NamedTimers; static ManagedStatic NamedGroupedTimers; -static Timer &getNamedRegionTimer(const std::string &Name) { +static Timer &getNamedRegionTimer(StringRef Name) { sys::SmartScopedLock L(*TimerLock); Timer &T = (*NamedTimers)[Name]; @@ -228,11 +228,10 @@ static Timer &getNamedRegionTimer(const std::string &Name) { return T; } -NamedRegionTimer::NamedRegionTimer(const std::string &Name) +NamedRegionTimer::NamedRegionTimer(StringRef Name) : TimeRegion(getNamedRegionTimer(Name)) {} -NamedRegionTimer::NamedRegionTimer(const std::string &Name, - const std::string &GroupName) +NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef GroupName) : TimeRegion(NamedGroupedTimers->get(Name, GroupName)) {} //===----------------------------------------------------------------------===// @@ -243,8 +242,8 @@ NamedRegionTimer::NamedRegionTimer(const std::string &Name, /// TimerGroup ctor/dtor and is protected by the TimerLock lock. static TimerGroup *TimerGroupList = 0; -TimerGroup::TimerGroup(const std::string &name) - : Name(name), FirstTimer(0) { +TimerGroup::TimerGroup(StringRef name) + : Name(name.begin(), name.end()), FirstTimer(0) { // Add the group to TimerGroupList. sys::SmartScopedLock L(*TimerLock);