From 4a4ad8f323939fe49df78d0f53958f8880687bf6 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Tue, 17 Apr 2018 11:16:05 -0700 Subject: [PATCH] [flang] Avoid a std::move() when emplacing new messages. Original-commit: flang-compiler/f18@39c0e1fdba24283db4f45a23d643b3db36ac6b42 Reviewed-on: https://github.com/flang-compiler/f18/pull/59 Tree-same-pre-rewrite: false --- flang/lib/parser/message.h | 25 ++++++++++--------------- flang/lib/parser/parse-state.h | 6 +++--- flang/lib/parser/reference-counted.h | 9 +++++---- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/flang/lib/parser/message.h b/flang/lib/parser/message.h index 39fd08f92213..d2bd9feb7971 100644 --- a/flang/lib/parser/message.h +++ b/flang/lib/parser/message.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace Fortran { namespace parser { @@ -179,24 +180,18 @@ public: } } - Message &Put(Message &&m) { - CHECK(IsValidLocation(m)); - if (messages_.empty()) { - messages_.emplace_front(std::move(m)); - last_ = messages_.begin(); - } else { - last_ = messages_.emplace_after(last_, std::move(m)); - } - return *last_; + void Put(Message &&m) { +// CHECK(IsValidLocation(m)); + last_ = messages_.emplace_after(last_, std::move(m)); + } + + template void Say(A &&... args) { + last_ = messages_.emplace_after(last_, std::forward(args)...); } void Annex(Messages &that) { if (!that.messages_.empty()) { - if (messages_.empty()) { - messages_ = std::move(that.messages_); - } else { - messages_.splice_after(last_, that.messages_); - } + messages_.splice_after(last_, that.messages_); last_ = that.last_; } } @@ -209,7 +204,7 @@ public: private: const CookedSource &cooked_; listType messages_; - iterator last_; // valid iff messages_ nonempty + iterator last_{messages_.before_begin()}; }; } // namespace parser } // namespace Fortran diff --git a/flang/lib/parser/parse-state.h b/flang/lib/parser/parse-state.h index 8289284e23fb..bdf491dc11d0 100644 --- a/flang/lib/parser/parse-state.h +++ b/flang/lib/parser/parse-state.h @@ -126,13 +126,13 @@ public: void Say(MessageExpectedText &&t) { return Say(p_, std::move(t)); } void Say(const char *at, MessageFixedText t) { - messages_.Put(Message{at, t, context_.get()}); + messages_.Say(at, t, context_.get()); } void Say(const char *at, MessageFormattedText &&t) { - messages_.Put(Message{at, std::move(t), context_.get()}); + messages_.Say(at, std::move(t), context_.get()); } void Say(const char *at, MessageExpectedText &&t) { - messages_.Put(Message{at, std::move(t), context_.get()}); + messages_.Say(at, std::move(t), context_.get()); } bool IsAtEnd() const { return p_ >= limit_; } diff --git a/flang/lib/parser/reference-counted.h b/flang/lib/parser/reference-counted.h index ab9131a1e2e7..8498dcd6a39a 100644 --- a/flang/lib/parser/reference-counted.h +++ b/flang/lib/parser/reference-counted.h @@ -29,15 +29,16 @@ public: CountedReference(const CountedReference &c) : p_{c.p_} { Take(); } CountedReference(CountedReference &&c) : p_{c.p_} { c.p_ = nullptr; } CountedReference &operator=(const CountedReference &c) { + c.Take(); Drop(); p_ = c.p_; - Take(); return *this; } CountedReference &operator=(CountedReference &&c) { - Drop(); - p_ = c.p_; + A *p{c.p_}; c.p_ = nullptr; + Drop(); + p_ = p; return *this; } ~CountedReference() { Drop(); } @@ -47,7 +48,7 @@ public: type *operator->() const { return p_; } private: - void Take() { + void Take() const { if (p_) { p_->TakeReference(); }