[poppler] std::unique_ptr

Carlos Garcia Campos carlosgc at gnome.org
Mon May 22 08:37:06 UTC 2017


Albert Astals Cid <aacid at kde.org> writes:

> El diumenge, 21 de maig de 2017, a les 14:20:54 CEST, Carlos Garcia Campos va 
> escriure:
>> I've started to play with using std::unique_ptr in poppler now that we
>> are using C++11. I've just submitted a new branch unique_ptr on top of
>> better_object branch. For now I've only changed Annots. 
>
> I'm really not a fan of 
>
> -    title = obj1.getString()->copy();
> +    title.reset(obj1.getString()->copy());
>
> my lizard brain does "ctrl+f" and then "title =", when i want to see who is 
> setting title.

No problem. It can be replaced by:

title = std::make_unique<GooString>(obj1.getString());

which is basically the same.

>
>> I'll move other
>> files in follow up commits when I find some more time.
>
>    if (obj1.isArray()) {
> -    interiorColor = new AnnotColor(obj1.getArray());
> -  } else {
> -    interiorColor = NULL;
> +    interiorColor = std::make_unique<AnnotColor>(obj1.getArray());
>    }
>
> this will abort if obj1 is not an array.

Why? There's no change in behavior there. If obj1 is an array, the
AnnotColor is created, otherwise we don't need to do anything, because
std::unique_ptr already initializes the pointer to nullptr on
construction.

> Cheers,
>   Albert
>
>> 
>> Regards,
>
>

-- 
Carlos Garcia Campos
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/poppler/attachments/20170522/b16609e4/attachment.sig>


More information about the poppler mailing list