Using std::make_shared (and in our case for the time being boost::make_shared)
is the preferred way of creating a std::shared_ptr. This is mainly due
to two aspects:

    - half the number of allocations required
    - potential of using less space, and better locality

Also a failed creation of the reference counted part of the object
will not make you leak the memory of the pointer object you just passed
to the share_ptr member function. (i.e. exception in the shared_ptr
member function).
---
 src/KeyMap.cpp                 | 2 +-
 src/OutputParams.cpp           | 2 +-
 src/ServerSocket.cpp           | 2 +-
 src/TextClass.cpp              | 5 +++--
 src/graphics/GraphicsCache.cpp | 2 +-
 src/graphics/PreviewLoader.cpp | 4 ++--
 src/insets/InsetNote.cpp       | 6 +++---
 src/insets/InsetTabular.cpp    | 8 ++++----
 src/support/ForkedCalls.cpp    | 5 ++---
 src/support/ForkedCalls.h      | 2 +-
 10 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp
index 50833c9..f2cecc8 100644
--- a/src/KeyMap.cpp
+++ b/src/KeyMap.cpp
@@ -141,7 +141,7 @@ void KeyMap::bind(KeySequence * seq, FuncRequest const & 
func, unsigned int r)
                newone->func.setOrigin(FuncRequest::KEYBOARD);
                newone->prefixes.reset();
        } else {
-               newone->prefixes.reset(new KeyMap);
+               newone->prefixes = make_shared<KeyMap>();
                newone->prefixes->bind(seq, func, r + 1);
        }
 }
diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp
index f8af8ad..163622d 100644
--- a/src/OutputParams.cpp
+++ b/src/OutputParams.cpp
@@ -23,7 +23,7 @@ OutputParams::OutputParams(Encoding const * enc)
          moving_arg(false), inulemcmd(false), local_font(0), 
master_language(0),
          encoding(enc), free_spacing(false), use_babel(false), 
use_polyglossia(false),
          use_indices(false), use_japanese(false), linelen(0), depth(0),
-         exportdata(new ExportData),
+         exportdata(make_shared<ExportData>()),
          inComment(false), inTableCell(NO), inFloat(NONFLOAT),
          inIndexEntry(false), inIPA(false), inDeletedInset(0),
          changeOfDeletedInset(Change::UNCHANGED),
diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp
index 4c34212..b18c837 100644
--- a/src/ServerSocket.cpp
+++ b/src/ServerSocket.cpp
@@ -112,7 +112,7 @@ void ServerSocket::serverCallback()
 
        // Register the new client.
        clients[client_fd] =
-               shared_ptr<LyXDataSocket>(new LyXDataSocket(client_fd));
+               make_shared<LyXDataSocket>(client_fd);
        theApp()->registerSocketCallback(
                client_fd,
                bind(&ServerSocket::dataCallback,
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 93eae96..9236ede 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -1434,8 +1434,9 @@ Layout TextClass::createBasicLayout(docstring const & 
name, bool unknown) const
 DocumentClassPtr getDocumentClass(
                LayoutFile const & baseClass, LayoutModuleList const & modlist)
 {
-       DocumentClassPtr doc_class =
-           DocumentClassPtr(new DocumentClass(baseClass));
+       // Since DocumentClass::DocumentClass(LayoutFile const &) is protected
+       // std::make_shared cannot be used here.
+       DocumentClassPtr doc_class(new DocumentClass(baseClass));
        LayoutModuleList::const_iterator it = modlist.begin();
        LayoutModuleList::const_iterator en = modlist.end();
        for (; it != en; ++it) {
diff --git a/src/graphics/GraphicsCache.cpp b/src/graphics/GraphicsCache.cpp
index f9eee10..97a0c88 100644
--- a/src/graphics/GraphicsCache.cpp
+++ b/src/graphics/GraphicsCache.cpp
@@ -112,7 +112,7 @@ void Cache::add(FileName const & file) const
                return;
        }
 
-       pimpl_->cache[file] = ItemPtr(new CacheItem(file));
+       pimpl_->cache[file] = make_shared<CacheItem>(file);
 }
 
 
diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index 6185681..82fb7ca 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -627,7 +627,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
 
        // Initiate the conversion from LaTeX to bitmap images files.
        ForkedCall::SignalTypePtr
-               convert_ptr(new ForkedCall::SignalType);
+               convert_ptr = make_shared<ForkedCall::SignalType>();
        convert_ptr->connect(bind(&Impl::finishedGenerating, this, _1, _2));
 
        ForkedCall call(buffer_.filePath());
@@ -683,7 +683,7 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int 
retval)
 
                // Add the image to the cache only if it's actually present
                if (file.isReadableFile()) {
-                       PreviewImagePtr ptr(new PreviewImage(parent_, snip, 
file, af));
+                       PreviewImagePtr ptr = 
make_shared<PreviewImage>(boost::ref(parent_), snip, file, af);
                        cache_[snip] = ptr;
 
                        newimages.push_back(ptr);
diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp
index 9b4ba57..b802ad5 100644
--- a/src/insets/InsetNote.cpp
+++ b/src/insets/InsetNote.cpp
@@ -228,7 +228,7 @@ void InsetNote::latex(otexstream & os, OutputParams const & 
runparams_in) const
        if (params_.type == InsetNoteParams::Comment) {
                runparams.inComment = true;
                // Ignore files that are exported inside a comment
-               runparams.exportdata.reset(new ExportData);
+               runparams.exportdata = make_shared<ExportData>();
        } 
 
        // the space after the comment in 'a[comment] b' will be eaten by the
@@ -262,7 +262,7 @@ int InsetNote::plaintext(odocstream & os,
        if (params_.type == InsetNoteParams::Comment) {
                runparams.inComment = true;
                // Ignore files that are exported inside a comment
-               runparams.exportdata.reset(new ExportData);
+               runparams.exportdata = make_shared<ExportData>();
        }
        os << '[' << buffer().B_("note") << ":\n";
        InsetText::plaintext(os, runparams);
@@ -282,7 +282,7 @@ int InsetNote::docbook(odocstream & os, OutputParams const 
& runparams_in) const
                os << "<remark>\n";
                runparams.inComment = true;
                // Ignore files that are exported inside a comment
-               runparams.exportdata.reset(new ExportData);
+               runparams.exportdata = make_shared<ExportData>();
        }
 
        int const n = InsetText::docbook(os, runparams);
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 6bdf72b..76c6370 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -567,7 +567,7 @@ Tabular::CellData::CellData(Buffer * buf)
          right_line(false),
          usebox(BOX_NONE),
          rotate(0),
-         inset(new InsetTableCell(buf))
+         inset(make_shared<InsetTableCell>(buf))
 {
        inset->setBuffer(*buf);
 }
@@ -592,7 +592,7 @@ Tabular::CellData::CellData(CellData const & cs)
          rotate(cs.rotate),
          align_special(cs.align_special),
          p_width(cs.p_width),
-         inset(static_cast<InsetTableCell *>(cs.inset->clone()))
+         inset(make_shared<InsetTableCell>(*cs.inset))
 {
 }
 
@@ -5853,8 +5853,8 @@ bool InsetTabular::pasteClipboard(Cursor & cur)
                                --c1;
                                continue;
                        }
-                       shared_ptr<InsetTableCell> inset(
-                               new 
InsetTableCell(*paste_tabular->cellInset(r1, c1)));
+                       shared_ptr<InsetTableCell> inset =
+                               
make_shared<InsetTableCell>(*paste_tabular->cellInset(r1, c1));
                        tabular.setCellInset(r2, c2, inset);
                        // FIXME?: why do we need to do this explicitly? (EL)
                        tabular.cellInset(r2, c2)->setBuffer(tabular.buffer());
diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp
index 0378b05..044f1a4 100644
--- a/src/support/ForkedCalls.cpp
+++ b/src/support/ForkedCalls.cpp
@@ -278,7 +278,7 @@ ForkedCall::ForkedCall(string const & path)
 int ForkedCall::startScript(Starttype wait, string const & what)
 {
        if (wait != Wait) {
-               retval_ = startScript(what, SignalTypePtr());
+               retval_ = startScript(what, 
make_shared<SignalTypePtr::value_type>());
                return retval_;
        }
 
@@ -456,8 +456,7 @@ void callback(pid_t, int);
 
 ForkedCall::SignalTypePtr add(string const & process)
 {
-       ForkedCall::SignalTypePtr ptr;
-       ptr.reset(new ForkedCall::SignalType);
+       ForkedCall::SignalTypePtr ptr = make_shared<ForkedCall::SignalType>();
        callQueue_.push(Process(process, ptr));
        if (!running_)
                startCaller();
diff --git a/src/support/ForkedCalls.h b/src/support/ForkedCalls.h
index 529f5c6..1c7c63a 100644
--- a/src/support/ForkedCalls.h
+++ b/src/support/ForkedCalls.h
@@ -153,7 +153,7 @@ public:
        ForkedCall(std::string const & path = empty_string());
        ///
        virtual shared_ptr<ForkedProcess> clone() const {
-               return shared_ptr<ForkedProcess>(new ForkedCall(*this));
+               return make_shared<ForkedCall>(*this);
        }
 
        /** Start the child process.
-- 
1.8.0.rc3.16.g8ead1bf


Reply via email to