From cba443f7bae6a4b471a16e014bd9cf4e76fca100 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sat, 12 Apr 2014 11:10:06 +0200 Subject: [PATCH] save allocations using casts to const --- alib2/src/regexp/Alternation.cpp | 4 ++-- alib2/src/regexp/Alternation.h | 2 +- alib2/src/regexp/Concatenation.cpp | 4 ++-- alib2/src/regexp/Concatenation.h | 2 +- alib2/src/regexp/Iteration.cpp | 4 ++-- alib2/src/regexp/Iteration.h | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/alib2/src/regexp/Alternation.cpp b/alib2/src/regexp/Alternation.cpp index 47940ba5a5..8f5c6618e7 100644 --- a/alib2/src/regexp/Alternation.cpp +++ b/alib2/src/regexp/Alternation.cpp @@ -44,8 +44,8 @@ Alternation::~Alternation() noexcept { elements.clear(); } -const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > Alternation::getElements() const { - return std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > >(elements.begin(), elements.end()); +const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > & Alternation::getElements() const { + return * reinterpret_cast<const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > * > (&elements); } void Alternation::insertElement(const RegExpElement& element) { diff --git a/alib2/src/regexp/Alternation.h b/alib2/src/regexp/Alternation.h index f76313d5f3..d5fc72c94b 100644 --- a/alib2/src/regexp/Alternation.h +++ b/alib2/src/regexp/Alternation.h @@ -39,7 +39,7 @@ public: /** * @return elements */ - const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > getElements() const; + const std::set<std::shared_ptr<const RegExpElement>, std::owner_less<std::shared_ptr<const RegExpElement> > > & getElements() const; /** * @param element to insert diff --git a/alib2/src/regexp/Concatenation.cpp b/alib2/src/regexp/Concatenation.cpp index 9e25ba6079..baff263883 100644 --- a/alib2/src/regexp/Concatenation.cpp +++ b/alib2/src/regexp/Concatenation.cpp @@ -43,8 +43,8 @@ Concatenation::~Concatenation() noexcept { elements.clear(); } -const std::vector<std::shared_ptr<const RegExpElement> > Concatenation::getElements() const { - return std::vector<std::shared_ptr<const RegExpElement> >(elements.begin(), elements.end()); +const std::vector<std::shared_ptr<const RegExpElement> > & Concatenation::getElements() const { + return * reinterpret_cast<const std::vector<std::shared_ptr<const RegExpElement> > * > (&elements); } void Concatenation::appendElement(const RegExpElement& element) { diff --git a/alib2/src/regexp/Concatenation.h b/alib2/src/regexp/Concatenation.h index 30b13510d4..504e4570e0 100644 --- a/alib2/src/regexp/Concatenation.h +++ b/alib2/src/regexp/Concatenation.h @@ -39,7 +39,7 @@ public: /** * @return elements */ - const std::vector<std::shared_ptr<const RegExpElement> > getElements() const; + const std::vector<std::shared_ptr<const RegExpElement> > & getElements() const; /** * @param element to append diff --git a/alib2/src/regexp/Iteration.cpp b/alib2/src/regexp/Iteration.cpp index 8a1017d3f1..06335296dd 100644 --- a/alib2/src/regexp/Iteration.cpp +++ b/alib2/src/regexp/Iteration.cpp @@ -42,8 +42,8 @@ regexp::Iteration::~Iteration() noexcept { } -const std::shared_ptr<const RegExpElement> Iteration::getElement() const { - return std::shared_ptr<const RegExpElement>(element); +const std::shared_ptr<const RegExpElement> & Iteration::getElement() const { + return * reinterpret_cast<const std::shared_ptr<const RegExpElement> * > (&element); } void Iteration::setElement(const RegExpElement& element) { diff --git a/alib2/src/regexp/Iteration.h b/alib2/src/regexp/Iteration.h index 16f134643b..8b1d8d5e0e 100644 --- a/alib2/src/regexp/Iteration.h +++ b/alib2/src/regexp/Iteration.h @@ -39,7 +39,7 @@ public: /** * @return element */ - const std::shared_ptr<const RegExpElement> getElement() const; + const std::shared_ptr<const RegExpElement> & getElement() const; /** * @param element to iterate -- GitLab