[llvm] r212678 - SpecialCaseList: use std::unique_ptr.

David Blaikie dblaikie at gmail.com
Wed Jul 9 22:11:18 PDT 2014


On Wed, Jul 9, 2014 at 8:55 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:
> Author: pcc
> Date: Wed Jul  9 22:55:02 2014
> New Revision: 212678
>
> URL: http://llvm.org/viewvc/llvm-project?rev=212678&view=rev
> Log:
> SpecialCaseList: use std::unique_ptr.
>
> Modified:
>     llvm/trunk/lib/Support/SpecialCaseList.cpp
>
> Modified: llvm/trunk/lib/Support/SpecialCaseList.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SpecialCaseList.cpp?rev=212678&r1=212677&r2=212678&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/SpecialCaseList.cpp (original)
> +++ llvm/trunk/lib/Support/SpecialCaseList.cpp Wed Jul  9 22:55:02 2014
> @@ -35,9 +35,7 @@ namespace llvm {
>  /// literal strings than Regex.
>  struct SpecialCaseList::Entry {
>    StringSet<> Strings;
> -  Regex *RegEx;
> -
> -  Entry() : RegEx(nullptr) {}
> +  std::unique_ptr<Regex> RegEx;
>
>    bool match(StringRef Query) const {
>      return Strings.count(Query) || (RegEx && RegEx->match(Query));
> @@ -147,23 +145,13 @@ bool SpecialCaseList::parse(const Memory
>      for (StringMap<std::string>::const_iterator II = I->second.begin(),
>                                                  IE = I->second.end();
>           II != IE; ++II) {
> -      Entries[I->getKey()][II->getKey()].RegEx = new Regex(II->getValue());
> +      Entries[I->getKey()][II->getKey()].RegEx.reset(new Regex(II->getValue()));

I'd personally favor "= make_unique<T>" rather than ".reset(new T".
It'd be nice if we could move towards a future in which raw 'new' is
treated with suspicion.

>      }
>    }
>    return true;
>  }
>
> -SpecialCaseList::~SpecialCaseList() {
> -  for (StringMap<StringMap<Entry> >::iterator I = Entries.begin(),
> -                                              E = Entries.end();
> -       I != E; ++I) {
> -    for (StringMap<Entry>::const_iterator II = I->second.begin(),
> -                                          IE = I->second.end();
> -         II != IE; ++II) {
> -      delete II->second.RegEx;
> -    }
> -  }
> -}
> +SpecialCaseList::~SpecialCaseList() {}
>
>  bool SpecialCaseList::inSection(const StringRef Section, const StringRef Query,
>                                  const StringRef Category) const {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list