@@ -1911,50 +1911,46 @@ SwiftLanguage::GetDemangledFunctionNameWithoutArguments(Mangled mangled) const {
19111911 return mangled_name;
19121912}
19131913
1914- static llvm::Expected<std::pair<std::string , DemangledNameInfo>>
1914+ static llvm::Expected<std::pair<llvm::StringRef , DemangledNameInfo>>
19151915GetAndValidateInfo (const SymbolContext &sc) {
19161916 Mangled mangled = sc.GetPossiblyInlinedFunctionName ();
19171917 if (!mangled)
19181918 return llvm::createStringError (" Function does not have a mangled name." );
19191919
1920- const char *mangled_name = mangled.GetMangledName ().AsCString (" " );
1921- auto [demangled_name, info] =
1922- SwiftLanguageRuntime::TrackedDemangleSymbolAsString (
1923- mangled_name, SwiftLanguageRuntime::eSimplified, &sc);
1924- info.PrefixRange .second =
1925- std::min (info.BasenameRange .first , info.ArgumentsRange .first );
1926- info.SuffixRange .first =
1927- std::max (info.BasenameRange .second , info.ArgumentsRange .second );
1928- info.SuffixRange .second = demangled_name.length ();
1929-
1920+ auto demangled_name =
1921+ mangled.GetDemangledName (nullptr , Mangled::eCompactName).GetStringRef ();
19301922 if (demangled_name.empty ())
19311923 return llvm::createStringError (
19321924 " Function '%s' does not have a demangled name." ,
19331925 mangled.GetMangledName ().AsCString (" " ));
19341926
1927+ const std::optional<DemangledNameInfo> &info = mangled.GetDemangledInfo ();
1928+ if (!info)
1929+ return llvm::createStringError (
1930+ " Function '%s' does not have demangled info." , demangled_name.data ());
1931+
19351932 // Function without a basename is nonsense.
1936- if (!info. hasBasename ())
1933+ if (!info-> hasBasename ())
19371934 return llvm::createStringError (
19381935 " DemangledInfo for '%s does not have basename range." ,
19391936 demangled_name.data ());
19401937
1941- return std::make_pair (demangled_name, info);
1938+ return std::make_pair (demangled_name, * info);
19421939}
19431940
1944- static llvm::Expected<std::string >
1941+ static llvm::Expected<llvm::StringRef >
19451942GetDemangledBasename (const SymbolContext &sc) {
19461943 auto info_or_err = GetAndValidateInfo (sc);
19471944 if (!info_or_err)
19481945 return info_or_err.takeError ();
19491946
19501947 auto [demangled_name, info] = *info_or_err;
19511948
1952- return demangled_name.substr (info.BasenameRange .first ,
1953- info.BasenameRange .second -
1954- info.BasenameRange .first );
1949+ return demangled_name.slice (info.BasenameRange .first ,
1950+ info.BasenameRange .second );
19551951}
19561952
1957- static llvm::Expected<std::string >
1953+ static llvm::Expected<llvm::StringRef >
19581954GetDemangledFunctionPrefix (const SymbolContext &sc) {
19591955 auto info_or_err = GetAndValidateInfo (sc);
19601956 if (!info_or_err)
@@ -1967,11 +1963,10 @@ GetDemangledFunctionPrefix(const SymbolContext &sc) {
19671963 " DemangledInfo for '%s does not have suffix range." ,
19681964 demangled_name.data ());
19691965
1970- return demangled_name.substr (
1971- info.PrefixRange .first , info.PrefixRange .second - info.PrefixRange .first );
1966+ return demangled_name.slice (info.PrefixRange .first , info.PrefixRange .second );
19721967}
19731968
1974- static llvm::Expected<std::string >
1969+ static llvm::Expected<llvm::StringRef >
19751970GetDemangledFunctionSuffix (const SymbolContext &sc) {
19761971 auto info_or_err = GetAndValidateInfo (sc);
19771972 if (!info_or_err)
@@ -1984,8 +1979,7 @@ GetDemangledFunctionSuffix(const SymbolContext &sc) {
19841979 " DemangledInfo for '%s does not have suffix range." ,
19851980 demangled_name.data ());
19861981
1987- return demangled_name.substr (
1988- info.SuffixRange .first , info.SuffixRange .second - info.SuffixRange .first );
1982+ return demangled_name.slice (info.SuffixRange .first , info.SuffixRange .second );
19891983}
19901984
19911985static bool PrintDemangledArgumentList (Stream &s, const SymbolContext &sc) {
@@ -2003,9 +1997,8 @@ static bool PrintDemangledArgumentList(Stream &s, const SymbolContext &sc) {
20031997 if (!info.hasArguments ())
20041998 return false ;
20051999
2006- s << demangled_name.substr (info.ArgumentsRange .first ,
2007- info.ArgumentsRange .second -
2008- info.ArgumentsRange .first );
2000+ s << demangled_name.slice (info.ArgumentsRange .first ,
2001+ info.ArgumentsRange .second );
20092002
20102003 return true ;
20112004}
0 commit comments