Skip to content

Commit 7d652fc

Browse files
committed
Use faster bit logic
1 parent cf92883 commit 7d652fc

File tree

8 files changed

+81
-56
lines changed

8 files changed

+81
-56
lines changed

final/output/tty/foptiattr.cpp

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,56 +39,76 @@ namespace finalcut
3939
namespace internal
4040
{
4141

42-
constexpr auto getReverseMask() noexcept -> uInt32
42+
template<typename F>
43+
constexpr auto createMask(F setter) noexcept -> uInt32
4344
{
4445
FCharAttribute mask{};
45-
mask.reverse = true;
46-
mask.standout = true;
46+
setter(mask);
4747
return FCharAttribute_to_uInt32(mask);
4848
}
4949

50-
constexpr auto getAttributeMask() noexcept -> uInt32
50+
constexpr void setReverseMask (FCharAttribute& attr) noexcept
5151
{
52-
FCharAttribute mask{};
53-
mask.bold = true;
54-
mask.dim = true;
55-
mask.italic = true;
56-
mask.underline = true;
57-
mask.blink = true;
58-
mask.reverse = true;
59-
mask.standout = true;
60-
mask.invisible = true;
61-
mask.protect = true;
62-
mask.crossed_out = true;
63-
mask.dbl_underline = true;
64-
mask.alt_charset = true;
65-
mask.pc_charset = true;
66-
return FCharAttribute_to_uInt32(mask);
52+
attr.reverse = true;
53+
attr.standout = true;
54+
}
55+
56+
constexpr void setAltCharsetMask (FCharAttribute& attr) noexcept
57+
{
58+
attr.alt_charset = true;
6759
}
6860

69-
constexpr auto getResetMask() noexcept -> uInt32
61+
constexpr void setPcCharsetMask (FCharAttribute& attr) noexcept
62+
{
63+
attr.pc_charset = true;
64+
}
65+
66+
constexpr void setAttributeMask (FCharAttribute& attr) noexcept
67+
{
68+
attr.bold = true;
69+
attr.dim = true;
70+
attr.italic = true;
71+
attr.underline = true;
72+
attr.blink = true;
73+
attr.reverse = true;
74+
attr.standout = true;
75+
attr.invisible = true;
76+
attr.protect = true;
77+
attr.crossed_out = true;
78+
attr.dbl_underline = true;
79+
attr.alt_charset = true;
80+
attr.pc_charset = true;
81+
}
82+
83+
constexpr void setResetMask (FCharAttribute& attr) noexcept
7084
{
7185
// Set bits that must not be reset
72-
FCharAttribute mask{};
73-
mask.transparent = true;
74-
mask.color_overlay = true;
75-
mask.inherit_background = true;
76-
mask.no_changes = true;
77-
mask.printed = true;
78-
return FCharAttribute_to_uInt32(mask);
86+
attr.transparent = true;
87+
attr.color_overlay = true;
88+
attr.inherit_background = true;
89+
attr.no_changes = true;
90+
attr.printed = true;
7991
}
8092

8193
struct var
8294
{
83-
static constexpr auto reverse_mask = getReverseMask();
84-
static constexpr auto attribute_mask = getAttributeMask();
85-
static constexpr auto reset_mask = getResetMask();
86-
static constexpr char sgr_39[] = {CSI "39m"};
87-
static constexpr char sgr_39_49[] = {CSI "39;49m"};
95+
static constexpr auto reverse_mask = createMask(setReverseMask);
96+
static constexpr auto alt_charset_mask = createMask(setAltCharsetMask);
97+
static constexpr auto pc_charset_mask = createMask(setPcCharsetMask);
98+
static constexpr auto attribute_mask = createMask(setAttributeMask);
99+
static constexpr auto alt_charset_reset_mask = ~alt_charset_mask;
100+
static constexpr auto pc_charset_reset_mask = ~pc_charset_mask;
101+
static constexpr auto reset_mask = createMask(setResetMask);
102+
static constexpr char sgr_39[] = {CSI "39m"};
103+
static constexpr char sgr_39_49[] = {CSI "39;49m"};
88104
};
89105

90106
constexpr uInt32 var::reverse_mask;
107+
constexpr uInt32 var::alt_charset_mask;
108+
constexpr uInt32 var::pc_charset_mask;
91109
constexpr uInt32 var::attribute_mask;
110+
constexpr uInt32 var::alt_charset_reset_mask;
111+
constexpr uInt32 var::pc_charset_reset_mask;
92112
constexpr uInt32 var::reset_mask;
93113
constexpr char var::sgr_39[];
94114
constexpr char var::sgr_39_49[];
@@ -468,7 +488,7 @@ auto FOptiAttr::changeAttribute (FChar& term, FChar& next) -> std::string
468488
deactivateAttributes (term, next);
469489
}
470490
else if ( F_attributes.on.cap
471-
&& (! term.attr.bit.pc_charset || alt_equal_pc_charset) )
491+
&& (! (term.attr.data & internal::var::pc_charset_mask) || alt_equal_pc_charset) )
472492
{
473493
changeAttributeSGR (term, next);
474494
}
@@ -780,9 +800,10 @@ inline auto FOptiAttr::unsetTermAttributes (FChar& term) noexcept -> bool
780800
//----------------------------------------------------------------------
781801
inline auto FOptiAttr::setTermAltCharset (FChar& term) noexcept -> bool
782802
{
783-
term.attr.bit.alt_charset = true;
803+
term.attr.data |= internal::var::alt_charset_mask;
784804

785-
if ( alt_equal_pc_charset && term.attr.bit.pc_charset )
805+
if ( alt_equal_pc_charset
806+
&& term.attr.data & internal::var::pc_charset_mask )
786807
return false;
787808

788809
return append_sequence(F_alt_charset.on.cap);
@@ -791,9 +812,10 @@ inline auto FOptiAttr::setTermAltCharset (FChar& term) noexcept -> bool
791812
//----------------------------------------------------------------------
792813
inline auto FOptiAttr::unsetTermAltCharset (FChar& term) noexcept -> bool
793814
{
794-
term.attr.bit.alt_charset = false;
815+
term.attr.data &= internal::var::alt_charset_reset_mask;
795816

796-
if ( alt_equal_pc_charset && term.attr.bit.pc_charset )
817+
if ( alt_equal_pc_charset
818+
&& term.attr.data & internal::var::pc_charset_mask )
797819
return false;
798820

799821
return append_sequence(F_alt_charset.off.cap);
@@ -802,9 +824,10 @@ inline auto FOptiAttr::unsetTermAltCharset (FChar& term) noexcept -> bool
802824
//----------------------------------------------------------------------
803825
inline auto FOptiAttr::setTermPCcharset (FChar& term) noexcept -> bool
804826
{
805-
term.attr.bit.pc_charset = true;
827+
term.attr.data |= internal::var::pc_charset_mask;
806828

807-
if ( alt_equal_pc_charset && term.attr.bit.alt_charset )
829+
if ( alt_equal_pc_charset
830+
&& term.attr.data & internal::var::alt_charset_mask )
808831
return false;
809832

810833
return append_sequence(F_pc_charset.on.cap);
@@ -813,9 +836,10 @@ inline auto FOptiAttr::setTermPCcharset (FChar& term) noexcept -> bool
813836
//----------------------------------------------------------------------
814837
inline auto FOptiAttr::unsetTermPCcharset (FChar& term) noexcept -> bool
815838
{
816-
term.attr.bit.pc_charset = false;
839+
term.attr.data &= internal::var::pc_charset_reset_mask;
817840

818-
if ( alt_equal_pc_charset && term.attr.bit.alt_charset )
841+
if ( alt_equal_pc_charset
842+
&& term.attr.data & internal::var::alt_charset_mask )
819843
return false;
820844

821845
return append_sequence(F_pc_charset.off.cap);
@@ -923,7 +947,8 @@ inline auto FOptiAttr::isDoubleUnderlineUsed ( const FChar& term
923947
inline auto FOptiAttr::isPCcharsetUsed ( const FChar& term
924948
, const FChar& next ) const noexcept -> bool
925949
{
926-
return ! term.attr.bit.pc_charset && next.attr.bit.pc_charset;
950+
return ! (term.attr.data & internal::var::pc_charset_mask)
951+
&& next.attr.data & internal::var::pc_charset_mask;
927952
}
928953

929954
//----------------------------------------------------------------------
@@ -932,10 +957,10 @@ inline auto FOptiAttr::isPCcharsetUsable ( FChar& term
932957
{
933958
if ( alt_equal_pc_charset
934959
&& F_pc_charset.on.cap
935-
&& next.attr.bit.alt_charset )
960+
&& next.attr.data & internal::var::alt_charset_mask )
936961
{
937962
term.attr.bit.pc_charset = next.attr.bit.pc_charset;
938-
changes.off.attr.bit.pc_charset = false;
963+
changes.off.attr.data &= internal::var::pc_charset_reset_mask;
939964
return false;
940965
}
941966

@@ -995,12 +1020,12 @@ inline void FOptiAttr::deactivateAttributes (FChar& term, FChar& next)
9951020
{
9961021
if ( F_attributes.off.cap )
9971022
{
998-
if ( changes.off.attr.bit.alt_charset ) // Required for rxvt terminals
1023+
if ( changes.off.attr.data & internal::var::alt_charset_mask ) // Required for rxvt terminals
9991024
unsetTermAltCharset(term);
10001025

10011026
unsetTermAttributes(term);
10021027

1003-
if ( changes.off.attr.bit.pc_charset )
1028+
if ( changes.off.attr.data & internal::var::pc_charset_mask )
10041029
unsetTermPCcharset(term);
10051030
}
10061031
else
@@ -1028,7 +1053,7 @@ inline void FOptiAttr::changeAttributeSGR (FChar& term, FChar& next)
10281053

10291054
const auto pc_charset_usable = isPCcharsetUsable(term, next);
10301055

1031-
if ( changes.off.attr.bit.pc_charset )
1056+
if ( changes.off.attr.data & internal::var::pc_charset_mask )
10321057
unsetTermPCcharset(term);
10331058

10341059
if ( isItalicsUsed(term, next) )

final/output/tty/ftermcapquirks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* *
44
* This file is part of the FINAL CUT widget toolkit *
55
* *
6-
* Copyright 2018-2024 Markus Gans *
6+
* Copyright 2018-2026 Markus Gans *
77
* *
88
* FINAL CUT is free software; you can redistribute it and/or modify *
99
* it under the terms of the GNU Lesser General Public License as *

final/output/tty/ftermoutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ inline void FTermOutput::charsetChanges (FChar& next_char) const
14141414
}
14151415

14161416
//----------------------------------------------------------------------
1417-
inline void FTermOutput::appendCharacter (FChar_iterator& next_char_iter)
1417+
inline void FTermOutput::appendCharacter (const FChar_iterator& next_char_iter)
14181418
{
14191419
const int term_width = vterm->size.width - 1;
14201420
const int term_height = vterm->size.height - 1;

final/output/tty/ftermoutput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class FTermOutput final : public FOutput
248248
void markAsPrinted (uInt, uInt, uInt) const noexcept;
249249
void newFontChanges (FChar&) const;
250250
void charsetChanges (FChar&) const;
251-
void appendCharacter (FChar_iterator&);
251+
void appendCharacter (const FChar_iterator&);
252252
void appendCharacter_n (FChar_iterator&, uInt);
253253
void appendChar (FChar&);
254254
void appendAttributes (FChar&);

final/util/fstring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ FString::FString (const UniChar& c)
152152
FString::FString (const wchar_t c)
153153
{
154154
if ( c )
155-
string.assign(1, static_cast<wchar_t>(c));
155+
string.assign(1, c);
156156
}
157157

158158
//----------------------------------------------------------------------
@@ -1160,7 +1160,7 @@ template <typename NumT>
11601160
inline auto FString::internal_setFormatedNumber (NumT value, FString separator) -> FString&
11611161
{
11621162
const auto is_negative = isNegative(value);
1163-
using SignedT = typename std::make_signed<NumT>::type;
1163+
using SignedT = typename std::make_signed_t<NumT>;
11641164
auto abs_value = is_negative
11651165
? uInt64(-(static_cast<SignedT>(value + 1))) + 1ULL
11661166
: uInt64(value);

final/vterm/fvterm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ inline void FVTerm::putMultiLayerAreaLine ( FChar* dst_char
18891889
const auto x = term_x - x_min;
18901890
const auto y = term_y - y_min;
18911891
const auto width = getFullAreaWidth(win);
1892-
const auto index = unsigned(y) * unsigned(width) + unsigned(x);
1892+
const auto index = y * width + x;
18931893

18941894
// Calculate the intersection of the line with the window
18951895
const auto start_idx = std::size_t(std::max(0, x_min - term_x));
@@ -1898,7 +1898,7 @@ inline void FVTerm::putMultiLayerAreaLine ( FChar* dst_char
18981898
// Store pre-calculated area line data
18991899
overlay_line_buffer.push_back
19001900
(
1901-
{ win->data.data(), unsigned(index), start_idx, end_idx }
1901+
{ win->data.data(), index, start_idx, end_idx }
19021902
);
19031903
}
19041904

final/widget/flistview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* *
44
* This file is part of the FINAL CUT widget toolkit *
55
* *
6-
* Copyright 2017-2024 Markus Gans *
6+
* Copyright 2017-2026 Markus Gans *
77
* *
88
* FINAL CUT is free software; you can redistribute it and/or modify *
99
* it under the terms of the GNU Lesser General Public License as *

test/ftermcapquirks-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* *
44
* This file is part of the FINAL CUT widget toolkit *
55
* *
6-
* Copyright 2018-2025 Markus Gans *
6+
* Copyright 2018-2026 Markus Gans *
77
* *
88
* FINAL CUT is free software; you can redistribute it and/or modify *
99
* it under the terms of the GNU Lesser General Public License as *

0 commit comments

Comments
 (0)