Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Nov 21, 2024
1 parent 0a0ea14 commit b433532
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 39 deletions.
6 changes: 3 additions & 3 deletions far/PluginA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,7 @@ static intptr_t WINAPI FarSendDlgMessageA(HANDLE hDlg, int OldMsg, int Param1, v
FarDialogItemData did{ sizeof(did), static_cast<size_t>(didA->PtrLength), text.data() };
intptr_t ret = pluginapi::apiSendDlgMessage(hDlg, DM_GETTEXT, Param1, &did);
didA->PtrLength = static_cast<int>(did.PtrLength);
(void)encoding::oem::get_bytes({ text.data(), did.PtrLength }, { didA->PtrData, static_cast<size_t>(didA->PtrLength + 1) });
(void)encoding::oem::get_bytes({ text.data(), did.PtrLength }, { didA->PtrData, static_cast<size_t>(didA->PtrLength) + 1 });
return ret;
}
case oldfar::DM_GETTEXTLENGTH: Msg = DM_GETTEXT; break;
Expand Down Expand Up @@ -3206,7 +3206,7 @@ static int WINAPI FarDialogExA(intptr_t PluginNumber, int X1, int Y1, int X2, in
NewDialogData.di = di.data();
NewDialogData.l = l.data();

Dialogs().emplace(hDlg, NewDialogData);
Dialogs().try_emplace(hDlg, NewDialogData);
SCOPE_EXIT{ Dialogs().erase(hDlg); };

const auto ret = pluginapi::apiDialogRun(hDlg);
Expand Down Expand Up @@ -3706,7 +3706,7 @@ static intptr_t WINAPI FarAdvControlA(intptr_t ModuleNumber, oldfar::ADVANCED_CO
{
std::vector<FarColor> Color(PaletteSize + 1);
pluginapi::apiAdvControl(GetPluginUuid(ModuleNumber), ACTL_GETARRAYCOLOR, Color.size(), Color.data());
Color.insert(Color.begin() + oldfar::COL_RESERVED0, FarColor{});
Color.emplace(Color.begin() + oldfar::COL_RESERVED0);
const auto OldColors = static_cast<LPBYTE>(Param);
std::ranges::transform(Color, OldColors, colors::FarColorToConsoleColor);
}
Expand Down
2 changes: 1 addition & 1 deletion far/colormix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ namespace colors
);
};

return Map.emplace(Color, std::ranges::min_element(Palette.begin() + Skip, Palette.end(), {}, distance) - Palette.begin()).first->second;
return Map.try_emplace(Color, std::ranges::min_element(Palette.begin() + Skip, Palette.end(), {}, distance) - Palette.begin()).first->second;
}

struct index_color_16
Expand Down
5 changes: 2 additions & 3 deletions far/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ namespace console_detail
static bool layout_has_altgr(HKL const Layout)
{
static std::unordered_map<HKL, bool> LayoutState;
const auto [Iterator, Inserted] = LayoutState.emplace(Layout, false);
const auto [Iterator, Inserted] = LayoutState.try_emplace(Layout, false);
if (!Inserted)
return Iterator->second;

Expand Down Expand Up @@ -1906,7 +1906,7 @@ namespace console_detail
return ::console.Write(CSI L"m"sv);
}

class cursor_suppressor: public hide_cursor
class cursor_suppressor: hide_cursor
{
public:
NONCOPYABLE(cursor_suppressor);
Expand Down Expand Up @@ -2941,7 +2941,6 @@ namespace console_detail

LOGINFO(L"Reinitializing"sv);
initialize();
return 1;
}

DWORD Written;
Expand Down
2 changes: 1 addition & 1 deletion far/diskmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void AddPluginItems(VMenu2 &ChDisk, int Pos, int DiskCount, bool SetSelec
#endif // NO_WRAPPER
LIF_NONE;

MenuInitItems.push_back({ std::move(strPluginText), Flags, HotKey, { pPlugin, Uuid } });
MenuInitItems.emplace_back(std::move(strPluginText), Flags, HotKey, plugin_item{ pPlugin, Uuid });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion far/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class positions_cache
return *Value;
}

const auto [Iterator, IsNew] = m_BigPositions.emplace(Position, 0);
const auto [Iterator, IsNew] = m_BigPositions.try_emplace(Position, 0);
if (IsNew)
Iterator->second = m_Accessor(Position, &m_State);

Expand Down
6 changes: 3 additions & 3 deletions far/filefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static void ParseAndAddMasks(std::map<string, int, string_sort::less_icase_t>& E
return;

const auto Ext = name_ext(FileName).second;
Extensions.emplace(Ext.empty()? L"*."s : concat(L'*', Ext), Check);
Extensions.emplace(Ext.empty()? L"*."sv : concat(L'*', Ext), Check);
}

static wchar_t GetCheck(filter_area const Type, const FileFilterParams& FFP)
Expand Down Expand Up @@ -555,7 +555,7 @@ static void ProcessSelection(VMenu2* const FilterList, filter_area const Area)
NewFilter.SetMask(true, Mask.find_first_of(L",;"sv, L"*."sv.size()) == string::npos? Mask : quote(Mask));
//Авто фильтры они только для файлов, папки не должны к ним подходить
NewFilter.SetAttr(true, 0, FILE_ATTRIBUTE_DIRECTORY);
const auto NewIterator = TempFilterData().emplace(Mask, std::move(NewFilter)).first;
const auto NewIterator = TempFilterData().try_emplace(Mask, std::move(NewFilter)).first;
CurFilterData = &NewIterator->second;
}
}
Expand Down Expand Up @@ -964,7 +964,7 @@ void filters::InitFilters()
}
}

TempFilterData().emplace(unquote(std::move(Mask)), std::move(NewItem));
TempFilterData().try_emplace(unquote(std::move(Mask)), std::move(NewItem));
}
}

Expand Down
4 changes: 2 additions & 2 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ FileList::FileList(private_tag, window_ptr Owner):
{
if (const auto& data = msg(lng::MPanelBracketsForLongName); data.size() > 1)
{
*openBracket = data[0];
*closeBracket = data[1];
openBracket = data[0];
closeBracket = data[1];
}

m_CurDir = os::fs::get_current_directory();
Expand Down
2 changes: 1 addition & 1 deletion far/filelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class FileList final: public Panel
Открывающий и закрывающий символ, которые используются для показа
имени, которое не помещается в панели. По умолчанию - фигурные скобки.
*/
wchar_t openBracket[2]{L'{'}, closeBracket[2]{L'}'};
wchar_t openBracket{L'{'}, closeBracket{L'}'};

string strOriginalCurDir;
string strPluginDizName;
Expand Down
2 changes: 1 addition & 1 deletion far/filemasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ bool filemasks::masks::operator==(const string_view FileName) const

Data.Match.assign(ALL_CONST_RANGE(Match.Matches));
for (const auto& [k, v]: NamedMatch.Matches)
Data.NamedMatch.emplace(k, v);
Data.NamedMatch.try_emplace(k, v);
return true;
}
}, m_Masks);
Expand Down
4 changes: 2 additions & 2 deletions far/filetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool ProcessLocalFileTypes(string_view const Name, string_view const ShortName,
{
for (const auto& i: Data.Matches)
{
Context.Variables.emplace(
Context.Variables.try_emplace(
far::format(L"RegexGroup{}"sv, &i - Data.Matches.data()),
get_match(Context.Name, i)
);
Expand All @@ -114,7 +114,7 @@ bool ProcessLocalFileTypes(string_view const Name, string_view const ShortName,
for (const auto& [GroupName, GroupNumber]: Data.NamedMatches)
{
const auto& Match = Data.Matches[GroupNumber];
Context.Variables.emplace(
Context.Variables.try_emplace(
far::format(L"RegexGroup{{{}}}"sv, GroupName),
get_match(Context.Name, Match)
);
Expand Down
2 changes: 1 addition & 1 deletion far/fnparce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ static bool InputVariablesDialog(string& strStr, subst_data& SubstData, string_v
if (!i.strHistory.empty() && i.strHistory != GenerateHistoryName(Index))
{
replace_icase(strTmpStr, L'%' + i.strHistory, i.strData);
SubstData.Variables->emplace(i.strHistory, i.strData);
SubstData.Variables->try_emplace(i.strHistory, i.strData);
}
}

Expand Down
2 changes: 1 addition & 1 deletion far/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static void LoadCustomStrings(string_view const FileName, unordered_string_map<s
break;

case lng_line_type::text:
Strings.emplace(std::move(SavedLabel), ConvertString(Line.Text));
Strings.try_emplace(std::move(SavedLabel), ConvertString(Line.Text));
SavedLabel.clear();
break;

Expand Down
2 changes: 1 addition & 1 deletion far/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void Manager::ExecuteNonModal(const window_ptr& NonModal)
void Manager::ExecuteModal(const window_ptr& Executed)
{
bool stop=false;
if (!m_Executed.emplace(Executed, &stop).second)
if (!m_Executed.try_emplace(Executed, &stop).second)
return;

const auto OriginalStartManager = StartManager;
Expand Down
6 changes: 3 additions & 3 deletions far/map_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static void read_vc(std::istream& Stream, unordered_string_set& Files, std::map<
const auto File = get_match(i.Str, m[3]);
Line.File = std::to_address(Files.emplace(File).first);

Symbols.emplace(Address, std::move(Line));
Symbols.try_emplace(Address, std::move(Line));
continue;
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ static void read_clang(std::istream& Stream, unordered_string_set& Files, std::m
Line.Name = get_match(i.Str, m[2]);
Line.File = std::to_address(Files.emplace(ObjName).first);
const auto Address = from_string<uintptr_t>(get_match(i.Str, m[1]), {}, 16);
Symbols.emplace(Address, std::move(Line));
Symbols.try_emplace(Address, std::move(Line));
continue;
}

Expand Down Expand Up @@ -292,7 +292,7 @@ static void read_gcc(std::istream& Stream, unordered_string_set& Files, std::map
Line.Name = get_match(i.Str, m[2]);
Line.File = std::to_address(Files.emplace(FileName).first);
const auto Address = from_string<uintptr_t>(get_match(i.Str, m[1]), {}, 16) + BaseAddress;
Symbols.emplace(Address, std::move(Line));
Symbols.try_emplace(Address, std::move(Line));
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion far/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool message_manager::dispatch()
const auto [Begin, End] = Handlers.equal_range(EventId);
for (const auto& [Key, Value]: std::ranges::subrange(Begin, End))
{
EligibleHandlers.emplace(Value, false);
EligibleHandlers.try_emplace(Value, false);
}
};

Expand Down
2 changes: 1 addition & 1 deletion far/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ static auto keyboard_layout_list_hr(std::span<HKL const> const List)
if (!from_string(*LayoutIdStr, LayoutId, {}, 16))
continue;

SpecialLayouts.emplace(LayoutId, Key);
SpecialLayouts.try_emplace(LayoutId, Key);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion far/platform.debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ namespace os::debug

const auto handler = [&](uintptr_t const Address, DWORD const InlineFrameContext)
{
Result.push_back({ Address, InlineFrameContext });
Result.emplace_back(Address, InlineFrameContext);
};

if (imports.StackWalkEx)
Expand Down
4 changes: 2 additions & 2 deletions far/platform.fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ namespace os::fs
// Mapped drives resolve to \Device\WinDfs\X:<whatever>\server\share
if (const auto DfsPrefix = L"\\Device\\WinDfs\\"sv; NtPath.starts_with(DfsPrefix))
{
const auto ServerStart = NtPath.find(L"\\", DfsPrefix.size());
const auto ServerStart = NtPath.find(L'\\', DfsPrefix.size());
FinalFilePath = NtPath.replace(0, ServerStart, 1, L'\\');
return true;
}
Expand Down Expand Up @@ -2395,7 +2395,7 @@ namespace os::fs
return true;

if (ElevationRequired(ELEVATION_READ_REQUEST))
return elevation::instance().get_disk_free_space(strPath.c_str(), UserFree, UserTotal, TotalFree);
return elevation::instance().get_disk_free_space(strPath, UserFree, UserTotal, TotalFree);

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion far/stddlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ void regex_playground()
for (const auto& [i, Index] : enumerate(Match.Matches))
{
ListStrings.emplace_back(far::format(L"${}: {}"sv, Index, match_str(i)));
ListItems.push_back({ i.start < 0? LIF_GRAYED : LIF_NONE, ListStrings.back().c_str(), 0, 0 });
ListItems.emplace_back(i.start < 0? LIF_GRAYED : LIF_NONE, ListStrings.back().c_str(), 0, 0);
}

for (const auto& [k, v] : NamedMatch.Matches)
Expand Down
2 changes: 1 addition & 1 deletion far/treelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ int TreeList::GetNextNavPos() const
{
int NextPos=m_CurFile;

if (static_cast<size_t>(m_CurFile + 1) < m_ListData.size())
if (static_cast<size_t>(m_CurFile) + 1 < m_ListData.size())
{
const auto CurDepth = m_ListData[m_CurFile].Depth;

Expand Down
16 changes: 8 additions & 8 deletions far/vmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ bool VMenu::AlignAnnotations()
if (!CheckFlags(VMENU_ENABLEALIGNANNOTATIONS)) return false;

const auto TextAreaWidth{ CalculateTextAreaWidth() };
if (TextAreaWidth <= 0 || TextAreaWidth + 2 <= 0) return false;
if (TextAreaWidth <= 0) return false;
const auto AlignPos{ (TextAreaWidth + 2) / 4 };

return SetAllItemsHPos(
Expand Down Expand Up @@ -2437,7 +2437,7 @@ void VMenu::DrawMenu()
if (Layout.Scrollbar)
{
set_color(Colors, color_indices::ScrollBar);
ScrollBar(Layout.Scrollbar.value(), Layout.ClientRect.top, Layout.ClientRect.height(), VisualTopPos, GetShowItemCount());
ScrollBar(*Layout.Scrollbar, Layout.ClientRect.top, Layout.ClientRect.height(), VisualTopPos, GetShowItemCount());
}
}

Expand Down Expand Up @@ -2608,7 +2608,7 @@ void VMenu::DrawRegularItem(const MenuItemEx& Item, const menu_layout& Layout, c
{
if (!Layout.TextArea) return;

const auto [TextAreaBegin, TextAreaWidth] { Layout.TextArea.value() };
const auto [TextAreaBegin, TextAreaWidth] { *Layout.TextArea };

GotoXY(TextAreaBegin, Y);

Expand Down Expand Up @@ -2671,16 +2671,16 @@ void VMenu::DrawRegularItem(const MenuItemEx& Item, const menu_layout& Layout, c
};

if (Layout.CheckMark)
DrawDecorator(Layout.CheckMark.value(), get_item_check_mark(Item, ColorIndices));
DrawDecorator(*Layout.CheckMark, get_item_check_mark(Item, ColorIndices));

if (Layout.LeftHScroll)
DrawDecorator(Layout.LeftHScroll.value(), get_item_left_hscroll(Item.HorizontalPosition < 0, ColorIndices));
DrawDecorator(*Layout.LeftHScroll, get_item_left_hscroll(Item.HorizontalPosition < 0, ColorIndices));

if (Layout.SubMenu)
DrawDecorator(Layout.SubMenu.value(), get_item_submenu(Item, ColorIndices));
DrawDecorator(*Layout.SubMenu, get_item_submenu(Item, ColorIndices));

if (Layout.RightHScroll)
DrawDecorator(Layout.RightHScroll.value(), get_item_right_hscroll(Item.HorizontalPosition + ItemTextSize > TextAreaWidth, ColorIndices));
DrawDecorator(*Layout.RightHScroll, get_item_right_hscroll(Item.HorizontalPosition + ItemTextSize > TextAreaWidth, ColorIndices));
}

int VMenu::CheckHighlights(wchar_t CheckSymbol, int StartPos) const
Expand Down Expand Up @@ -3263,7 +3263,7 @@ void VMenu::EnableFilter(bool const Enable)
int VMenu::CalculateTextAreaWidth() const
{
const auto TextArea = menu_layout{ *this }.TextArea;
return TextArea ? TextArea.value().second : 0;
return TextArea? TextArea->second : 0;
}

size_t VMenu::Text(string_view const Str) const
Expand Down

0 comments on commit b433532

Please sign in to comment.