From 258cacf7c5b23052f6bfde34ccaef2edb178b98f Mon Sep 17 00:00:00 2001 From: Nicholas Guriev Date: Fri, 8 Apr 2022 18:35:32 +0300 Subject: [PATCH] Avoid conditional branching on uninitialized values C++ initializes members in the order in which they are defined in class. So the order is important if the members are accessed by other initializers or methods called from them. Class BoxLayerWidget: _roundRect is initialized based on _layerType through the st() method. Class Checkbox: Arguments of _text constructor depend on _checkAlignment through the countTextMinWidth and the checkRect methods. --- ui/layers/box_layer_widget.h | 2 +- ui/widgets/checkbox.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/layers/box_layer_widget.h b/ui/layers/box_layer_widget.h index 893e220..016ad44 100644 --- a/ui/layers/box_layer_widget.h +++ b/ui/layers/box_layer_widget.h @@ -128,6 +128,7 @@ private: const style::Box *_st = nullptr; not_null _layer; + bool _layerType = false; int _fullHeight = 0; bool _noContentMargin = false; @@ -140,7 +141,6 @@ private: rpl::variable _additionalTitle; int _titleLeft = 0; int _titleTop = 0; - bool _layerType = false; bool _closeByOutsideClick = true; std::vector> _buttons; diff --git a/ui/widgets/checkbox.h b/ui/widgets/checkbox.h index 03a2b2b..9ffe452 100644 --- a/ui/widgets/checkbox.h +++ b/ui/widgets/checkbox.h @@ -228,8 +228,8 @@ private: rpl::event_stream _checkedChanges; QPixmap _checkCache; - Text::String _text; style::align _checkAlignment = style::al_left; + Text::String _text; int _allowTextLines = 1; bool _textBreakEverywhere = false;