[llvm] 29560a8 - [Support] Make UniqueStringSaver wrap a StringSet

Eric Christopher via llvm-commits llvm-commits at lists.llvm.org
Thu May 14 20:19:30 PDT 2020


Hey Ben,

I reverted this a little bit ago. It seemed to be causing asan failures in
clang tooling. I'll follow up with you offline for an easy repro.

-eric

On Thu, May 14, 2020 at 8:14 AM Benjamin Kramer via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Benjamin Kramer
> Date: 2020-05-14T17:11:44+02:00
> New Revision: 29560a89ddcaf3af9b8a73d98d968a0911d21e27
>
> URL:
> https://github.com/llvm/llvm-project/commit/29560a89ddcaf3af9b8a73d98d968a0911d21e27
> DIFF:
> https://github.com/llvm/llvm-project/commit/29560a89ddcaf3af9b8a73d98d968a0911d21e27.diff
>
> LOG: [Support] Make UniqueStringSaver wrap a StringSet
>
> This is slightly more efficient while providing exactly the same
> semantics.
>
> Added:
>
>
> Modified:
>     llvm/include/llvm/Support/StringSaver.h
>     llvm/lib/Support/StringSaver.cpp
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/include/llvm/Support/StringSaver.h
> b/llvm/include/llvm/Support/StringSaver.h
> index c54044e3986c..b6b3c054d07d 100644
> --- a/llvm/include/llvm/Support/StringSaver.h
> +++ b/llvm/include/llvm/Support/StringSaver.h
> @@ -9,7 +9,7 @@
>  #ifndef LLVM_SUPPORT_STRINGSAVER_H
>  #define LLVM_SUPPORT_STRINGSAVER_H
>
> -#include "llvm/ADT/DenseSet.h"
> +#include "llvm/ADT/StringSet.h"
>  #include "llvm/ADT/StringRef.h"
>  #include "llvm/ADT/Twine.h"
>  #include "llvm/Support/Allocator.h"
> @@ -36,12 +36,8 @@ class StringSaver final {
>  ///
>  /// Compared to StringSaver, it does more work but avoids saving the same
> string
>  /// multiple times.
> -///
> -/// Compared to StringPool, it performs fewer allocations but doesn't
> support
> -/// refcounting/deletion.
>  class UniqueStringSaver final {
> -  StringSaver Strings;
> -  llvm::DenseSet<llvm::StringRef> Unique;
> +  StringSet<BumpPtrAllocator &> Strings;
>
>  public:
>    UniqueStringSaver(BumpPtrAllocator &Alloc) : Strings(Alloc) {}
>
> diff  --git a/llvm/lib/Support/StringSaver.cpp
> b/llvm/lib/Support/StringSaver.cpp
> index f7ccfb97ea79..999f37a9a75d 100644
> --- a/llvm/lib/Support/StringSaver.cpp
> +++ b/llvm/lib/Support/StringSaver.cpp
> @@ -19,8 +19,5 @@ StringRef StringSaver::save(StringRef S) {
>  }
>
>  StringRef UniqueStringSaver::save(StringRef S) {
> -  auto R = Unique.insert(S);
> -  if (R.second)                 // cache miss, need to actually save the
> string
> -    *R.first = Strings.save(S); // safe replacement with equal value
> -  return *R.first;
> +  return Strings.insert(S).first->getKey();
>  }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200514/63eb5197/attachment.html>


More information about the llvm-commits mailing list