[PATCH] D40170: [llvm-tblgen] - Stop using std::string in RecordKeeper.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 07:32:35 PST 2017


IDK much about Tablegen, but this code looks functionally equivalent but
strictly better sylistically, so lgtm

On Mon, Nov 20, 2017 at 6:04 AM George Rimar via Phabricator <
reviews at reviews.llvm.org> wrote:

> grimar updated this revision to Diff 123572.
> grimar retitled this revision from "[llvm-tblgen] - Stop using std:string
> in RecordKeeper." to "[llvm-tblgen] - Stop using std::string in
> RecordKeeper.".
> grimar added a comment.
>
> - Use StringRef in `Tag` instead of `std::string*'. (`Tag` remembers ID of
> Classes/Defs from `Record` and since patch changes type of map key from
> `std::string` to `StringRef`, this place should be updated.)
>
>
> https://reviews.llvm.org/D40170
>
> Files:
>   include/llvm/TableGen/Record.h
>   utils/TableGen/CTagsEmitter.cpp
>
>
> Index: utils/TableGen/CTagsEmitter.cpp
> ===================================================================
> --- utils/TableGen/CTagsEmitter.cpp
> +++ utils/TableGen/CTagsEmitter.cpp
> @@ -28,18 +28,17 @@
>
>  class Tag {
>  private:
> -  const std::string *Id;
> +  StringRef Id;
>    SMLoc Loc;
>  public:
> -  Tag(const std::string &Name, const SMLoc Location)
> -      : Id(&Name), Loc(Location) {}
> -  int operator<(const Tag &B) const { return *Id < *B.Id; }
> +  Tag(StringRef Name, const SMLoc Location) : Id(Name), Loc(Location) {}
> +  int operator<(const Tag &B) const { return Id < B.Id; }
>    void emit(raw_ostream &OS) const {
>      const MemoryBuffer *CurMB =
>          SrcMgr.getMemoryBuffer(SrcMgr.FindBufferContainingLoc(Loc));
>      auto BufferName = CurMB->getBufferIdentifier();
>      std::pair<unsigned, unsigned> LineAndColumn =
> SrcMgr.getLineAndColumn(Loc);
> -    OS << *Id << "\t" << BufferName << "\t" << LineAndColumn.first <<
> "\n";
> +    OS << Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n";
>    }
>  };
>
> Index: include/llvm/TableGen/Record.h
> ===================================================================
> --- include/llvm/TableGen/Record.h
> +++ include/llvm/TableGen/Record.h
> @@ -1525,7 +1525,7 @@
>  };
>
>  class RecordKeeper {
> -  using RecordMap = std::map<std::string, std::unique_ptr<Record>>;
> +  using RecordMap = std::map<StringRef, std::unique_ptr<Record>>;
>    RecordMap Classes, Defs;
>
>  public:
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171120/07118e19/attachment.html>


More information about the llvm-commits mailing list