diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-07-29 07:08:44 +0000 | 
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-07-29 07:08:44 +0000 | 
| commit | b49994ad7edf36c8377460d70e9f3069de41a8f1 (patch) | |
| tree | 811cdf224601b80ae60c4814bfc278e3c91207f6 /llvm/lib/Support | |
| parent | a94f58aee5c813d0bd8f2da4788043ce42c1d475 (diff) | |
| download | bcm5719-llvm-b49994ad7edf36c8377460d70e9f3069de41a8f1.tar.gz bcm5719-llvm-b49994ad7edf36c8377460d70e9f3069de41a8f1.zip  | |
Twines: Support numeric conversion directly (uitostr, etc).
 - Provides static constructors for doing number to string conversions without
   using temporaries.
 - There are several ways to do this, I think given the Twine constraints this
   is the simplest one.
 - One FIXME for fast number -> hex conversion.
 - Added another comment on one last major bit of perf work Twines need, which
   is to make raw_svector_ostream more efficient.
llvm-svn: 77445
Diffstat (limited to 'llvm/lib/Support')
| -rw-r--r-- | llvm/lib/Support/Twine.cpp | 48 | 
1 files changed, 37 insertions, 11 deletions
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp index 4c34d279e8f..c9e5f2401ec 100644 --- a/llvm/lib/Support/Twine.cpp +++ b/llvm/lib/Support/Twine.cpp @@ -19,6 +19,13 @@ std::string Twine::str() const {  }  void Twine::toVector(SmallVectorImpl<char> &Out) const { +  // FIXME: This is very inefficient, since we are creating a large raw_ostream +  // buffer -- hitting malloc, which we were supposed to avoid -- all when we +  // have this pretty little small vector available. +  // +  // The best way to fix this is to make raw_svector_ostream do the right thing +  // and be efficient, by augmenting the base raw_ostream with the ability to +  // have the buffer managed by a concrete implementation.    raw_svector_ostream OS(Out);    print(OS);  } @@ -28,6 +35,9 @@ void Twine::printOneChild(raw_ostream &OS, const void *Ptr,    switch (Kind) {    case Twine::NullKind: break;    case Twine::EmptyKind: break; +  case Twine::TwineKind: +    static_cast<const Twine*>(Ptr)->print(OS);  +    break;    case Twine::CStringKind:       OS << static_cast<const char*>(Ptr);       break; @@ -37,8 +47,15 @@ void Twine::printOneChild(raw_ostream &OS, const void *Ptr,    case Twine::StringRefKind:      OS << *static_cast<const StringRef*>(Ptr);       break; -  case Twine::TwineKind: -    static_cast<const Twine*>(Ptr)->print(OS);  +  case Twine::UDecKind: +    OS << *static_cast<const uint64_t*>(Ptr); +    break; +  case Twine::SDecKind: +    OS << *static_cast<const int64_t*>(Ptr); +    break; +  case Twine::UHexKind: +    // FIXME: Add raw_ostream functionality for this. +    OS << ::utohexstr(*static_cast<const uint64_t*>(Ptr));      break;    }  } @@ -50,21 +67,30 @@ void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr,      OS << "null"; break;    case Twine::EmptyKind:      OS << "empty"; break; +  case Twine::TwineKind: +    OS << "rope:"; +    static_cast<const Twine*>(Ptr)->printRepr(OS); +    break;    case Twine::CStringKind: -    OS << "cstring:\""  -       << static_cast<const char*>(Ptr) << "\"";  +    OS << "cstring:\"" +       << static_cast<const char*>(Ptr) << "\"";      break;    case Twine::StdStringKind: -    OS << "std::string:\""  -       << *static_cast<const std::string*>(Ptr) << "\"";  +    OS << "std::string:\"" +       << static_cast<const std::string*>(Ptr) << "\"";      break;    case Twine::StringRefKind: -    OS << "stringref:\""  -       << *static_cast<const StringRef*>(Ptr) << "\"";  +    OS << "stringref:\"" +       << static_cast<const StringRef*>(Ptr) << "\"";      break; -  case Twine::TwineKind: -    OS << "rope:"; -    static_cast<const Twine*>(Ptr)->printRepr(OS); +  case Twine::UDecKind: +    OS << "udec:" << static_cast<const uint64_t*>(Ptr) << "\""; +    break; +  case Twine::SDecKind: +    OS << "sdec:" << static_cast<const int64_t*>(Ptr) << "\""; +    break; +  case Twine::UHexKind: +    OS << "uhex:" << static_cast<const uint64_t*>(Ptr) << "\"";      break;    }  }  | 

