[flang] Remove unnecessary unique_ptr.

The unique_ptr around the vector of char was unnecessary. We can just
move the vector itself and it still keeps the same stream of chars.

Original-commit: flang-compiler/f18@24672adba9
Reviewed-on: https://github.com/flang-compiler/f18/pull/149
This commit is contained in:
Tim Keith 2018-07-27 08:12:37 -07:00
parent 6f4f772685
commit 11225c978b
3 changed files with 12 additions and 13 deletions

View file

@ -303,19 +303,19 @@ const AllSources::Origin &AllSources::MapToOrigin(Provenance at) const {
}
ProvenanceRange CookedSource::GetProvenanceRange(CharBlock cookedRange) const {
ProvenanceRange first{provenanceMap_.Map(cookedRange.begin() - &(*data_)[0])};
ProvenanceRange first{provenanceMap_.Map(cookedRange.begin() - &data_[0])};
if (cookedRange.size() <= first.size()) {
return first.Prefix(cookedRange.size());
}
ProvenanceRange last{provenanceMap_.Map(cookedRange.end() - &(*data_)[0])};
ProvenanceRange last{provenanceMap_.Map(cookedRange.end() - &data_[0])};
return {first.start(), last.start() - first.start()};
}
void CookedSource::Marshal() {
CHECK(provenanceMap_.size() == buffer_.size());
provenanceMap_.Put(allSources_.AddCompilerInsertion("(after end of source)"));
data_ = std::make_unique<std::vector<char>>(buffer_.size());
char *p{&(*data_)[0]};
data_.resize(buffer_.size());
char *p{&data_[0]};
for (char ch : buffer_) {
*p++ = ch;
}

View file

@ -184,14 +184,14 @@ class CookedSource {
public:
explicit CookedSource(AllSources &sources) : allSources_{sources} {}
std::size_t size() const { return data_->size(); }
const char &operator[](std::size_t n) const { return (*data_)[n]; }
const char &at(std::size_t n) const { return data_->at(n); }
std::size_t size() const { return data_.size(); }
const char &operator[](std::size_t n) const { return data_[n]; }
const char &at(std::size_t n) const { return data_.at(n); }
AllSources &allSources() const { return allSources_; }
bool IsValid(const char *p) const {
return p >= &data_->front() && p <= &data_->back() + 1;
return p >= &data_.front() && p <= &data_.back() + 1;
}
bool IsValid(CharBlock range) const {
return !range.empty() && IsValid(range.begin()) && IsValid(range.end() - 1);
@ -211,14 +211,13 @@ public:
provenanceMap_.Put(pm);
}
void Marshal(); // marshals all text into one contiguous block
std::unique_ptr<std::vector<char>> MoveChars() { return std::move(data_); }
std::vector<char> MoveChars() { return std::move(data_); }
std::ostream &Dump(std::ostream &) const;
private:
AllSources &allSources_;
CharBuffer buffer_; // before Marshal()
// all source, prescanned and preprocessed:
std::unique_ptr<std::vector<char>> data_;
std::vector<char> data_; // all of it, prescanned and preprocessed
OffsetToProvenanceMappings provenanceMap_;
};

View file

@ -107,7 +107,7 @@ public:
// For modules read from module files, this is the stream of characters
// that are referenced by SourceName objects.
void set_chars(std::unique_ptr<std::vector<char>> chars) {
void set_chars(std::vector<char> chars) {
chars_ = std::move(chars);
}
@ -118,7 +118,7 @@ private:
std::list<Scope> children_;
mapType symbols_;
std::list<DerivedTypeSpec> derivedTypeSpecs_;
std::unique_ptr<std::vector<char>> chars_;
std::vector<char> chars_;
// Storage for all Symbols. Every Symbol is in allSymbols and every Symbol*
// or Symbol& points to one in there.