Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4228)

Issue 573500043: Issue 5732: Use unique_ptr in layout code (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
4 years, 2 months ago by Dan Eble
Modified:
4 years, 2 months ago
Reviewers:
dak, hahnjo
CC:
lilypond-devel_gnu.org
Visibility:
Public.

Description

https://sourceforge.net/p/testlilyissues/issues/5732/ Use std::unique_ptr instead of manually managed raw pointers. I suggest beginning the review in accidental-placement.cc The algorithm in stagger_apes () took me the most time to come to terms with. With unique_ptr, it's much easier to be confident that there isn't a memory leak there. unique_ptr deletes its object when it goes out of scope. Transferring ownership of the object to another instance of unique_ptr is done with std::move(). A unique_ptr can not be copied, but one can get an alias (a raw pointer) from it with p.get(). Using unique_ptr makes the flower junk_pointers() function unnecessary. I can't remove junk_pointers() yet because MIDI code still uses it, and I don't want to wade into that high water now. I'm aware that some lines are longer than 80 characters. I plan to try clang-format after Han-Wen's config file makes it through the countdown.

Patch Set 1 #

Total comments: 5
Unified diffs Side-by-side diffs Delta from patch set Stats (+86 lines, -63 lines) Patch
M lily/accidental-placement.cc View 13 chunks +31 lines, -29 lines 0 comments Download
M lily/beam-quanting.cc View 11 chunks +16 lines, -13 lines 2 comments Download
M lily/include/beam-scoring-problem.hh View 4 chunks +11 lines, -5 lines 0 comments Download
M lily/include/slur-configuration.hh View 2 chunks +3 lines, -1 line 0 comments Download
M lily/include/slur-scoring.hh View 3 chunks +5 lines, -2 lines 0 comments Download
M lily/slur-configuration.cc View 2 chunks +3 lines, -2 lines 0 comments Download
M lily/slur-scoring.cc View 5 chunks +5 lines, -5 lines 0 comments Download
M lily/system-start-delimiter-engraver.cc View 7 chunks +12 lines, -6 lines 3 comments Download

Messages

Total messages: 9
hahnjo
Just scanned the code, don't take this as a full review. In general I'm a ...
4 years, 2 months ago (2020-02-03 17:57:53 UTC) #1
dak
Stupid question: unique_ptr has the purpose of deallocating memory when the last reference is gone. ...
4 years, 2 months ago (2020-02-03 18:01:09 UTC) #2
hahnjo
On 2020/02/03 18:01:09, dak wrote: > Stupid question: unique_ptr has the purpose of deallocating memory ...
4 years, 2 months ago (2020-02-03 18:13:00 UTC) #3
Dan Eble
On 2020/02/03 18:01:09, dak wrote: > Stupid question: unique_ptr has the purpose of deallocating memory ...
4 years, 2 months ago (2020-02-03 18:27:23 UTC) #4
dak
On 2020/02/03 18:13:00, hahnjo wrote: > On 2020/02/03 18:01:09, dak wrote: > > Stupid question: ...
4 years, 2 months ago (2020-02-03 18:27:27 UTC) #5
dak
On 2020/02/03 18:27:27, dak wrote: > On 2020/02/03 18:13:00, hahnjo wrote: > > On 2020/02/03 ...
4 years, 2 months ago (2020-02-03 18:41:53 UTC) #6
Dan Eble
Thanks for the reviews, g https://codereview.appspot.com/573500043/diff/561420043/lily/beam-quanting.cc File lily/beam-quanting.cc (right): https://codereview.appspot.com/573500043/diff/561420043/lily/beam-quanting.cc#newcode1049 lily/beam-quanting.cc:1049: configs.clear (); On 2020/02/03 ...
4 years, 2 months ago (2020-02-03 18:53:45 UTC) #7
Dan Eble
On 2020/02/03 18:53:45, Dan Eble wrote: > Thanks for the reviews, g ... guys. (A ...
4 years, 2 months ago (2020-02-03 18:55:44 UTC) #8
hahnjo
4 years, 2 months ago (2020-02-03 18:58:25 UTC) #9
On 2020/02/03 18:53:45, Dan Eble wrote:
>
https://codereview.appspot.com/573500043/diff/561420043/lily/system-start-del...
> File lily/system-start-delimiter-engraver.cc (right):
> 
>
https://codereview.appspot.com/573500043/diff/561420043/lily/system-start-del...
> lily/system-start-delimiter-engraver.cc:149: (new Bracket_nesting_staff (0)));
> On 2020/02/03 17:57:52, hahnjo wrote:
> > Can you check if
> > children_.emplace_back (new Bracket_nesting_staff (0));
> > works? This would be much neater
> 
> It compiles, but it raises its own flag to reviewers because it does not show
> that the new object is managed by a smart pointer.

Fair point. That was already settled in my head, but probably only because of
the context.

> If I had C++14, I would have used std::make_unique<Bracket_nesting_staff> (0)
to
> avoid repeating the class name.  We can define our own make_unique if we want
> to, but I don't think it should be done in this patch.

Agreed.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b