forked from OSchip/llvm-project
[flang] Avoid a std::move() when emplacing new messages.
Original-commit: flang-compiler/f18@39c0e1fdba Reviewed-on: https://github.com/flang-compiler/f18/pull/59 Tree-same-pre-rewrite: false
This commit is contained in:
parent
8aa47941ee
commit
4a4ad8f323
|
@ -12,6 +12,7 @@
|
|||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
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<typename... A> void Say(A &&... args) {
|
||||
last_ = messages_.emplace_after(last_, std::forward<A>(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
|
||||
|
|
|
@ -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_; }
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue