[vlc-devel] [PATCH 1/2] adaptive: avoid using global static objects

Alexandre Janniaux ajanni at videolabs.io
Thu Apr 1 15:00:52 UTC 2021


Hi,

Maybe EmptyString can be removed and getAttributeValue could
return a pointer (to be able to return nullptr) in that case?

There´s not much reason to remove the static because of the
allocator than add the static to avoid duplicating a std::string
in every XML node, which would result in an increase of memory
usage for nothing, so removing the need for Node::EmptyString
looks much better, but unfortunately there´s no string_view in
what we allow and no optional to avoid sentinel values, leaving
only pointer solution in vanilla C++ if I´m not wrong, or wrapper
for the value.

Regards,
--
Alexandre Janniaux
Videolabs

On Thu, Apr 01, 2021 at 12:34:59PM +0200, Steve Lhomme wrote:
> This avoids calling a C++ allocator early or a C++ deallocator late in the
> lifetime of the module/program.
>
> In this case the EmptyString doesn't need to be static, just const.
> ---
>  modules/demux/adaptive/xml/Node.cpp | 2 --
>  modules/demux/adaptive/xml/Node.h   | 2 +-
>  2 files changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/modules/demux/adaptive/xml/Node.cpp b/modules/demux/adaptive/xml/Node.cpp
> index 1d9cf0e5857..e2ef962cd5c 100644
> --- a/modules/demux/adaptive/xml/Node.cpp
> +++ b/modules/demux/adaptive/xml/Node.cpp
> @@ -33,8 +33,6 @@
>
>  using namespace adaptive::xml;
>
> -const std::string   Node::EmptyString = "";
> -
>  Node::Node() :
>      type( -1 )
>  {
> diff --git a/modules/demux/adaptive/xml/Node.h b/modules/demux/adaptive/xml/Node.h
> index d40b8875d8a..5a9a5cb6502 100644
> --- a/modules/demux/adaptive/xml/Node.h
> +++ b/modules/demux/adaptive/xml/Node.h
> @@ -55,7 +55,7 @@ namespace adaptive
>                  std::vector<std::string>            toString(int) const;
>
>              private:
> -                static const std::string            EmptyString;
> +                const std::string                   EmptyString;
>                  std::vector<Node *>                 subNodes;
>                  std::map<std::string, std::string>  attributes;
>                  std::string                         name;
> --
> 2.29.2
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list