Skip to content

Commit

Permalink
function_ref, clang warnings, new fmt version
Browse files Browse the repository at this point in the history
- std::function replaced with function_ref where possible. Something (somewhere, sometime) will work faster. Probably.
- clang warnings.
- new version of fmt.
  • Loading branch information
alabuzhev committed Dec 26, 2018
1 parent e5882e2 commit c261b6a
Show file tree
Hide file tree
Showing 72 changed files with 647 additions and 636 deletions.
15 changes: 8 additions & 7 deletions far/PluginA.cpp
Expand Up @@ -60,6 +60,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "platform.env.hpp"
#include "platform.memory.hpp"

#include "common/function_ref.hpp"
#include "common/null_iterator.hpp"
#include "common/range.hpp"
#include "common/scope_exit.hpp"
Expand Down Expand Up @@ -724,7 +725,7 @@ static PluginPanelItem* ConvertAnsiPanelItemsToUnicode(range<oldfar::PluginPanel
Dst.AllocationSize = static_cast<unsigned long long>(Src.PackSize) + (static_cast<unsigned long long>(Src.PackSizeHigh) << 32);
Dst.FileName = AnsiToUnicode(Src.FindData.cFileName);
Dst.AlternateFileName = AnsiToUnicode(Src.FindData.cAlternateFileName);
};
}
return Result.release();
}

Expand Down Expand Up @@ -925,7 +926,7 @@ static void AnsiVBufToUnicode(CHAR_INFO* VBufA, FAR_CHAR_INFO* VBuf, size_t Size
AnsiToUnicodeBin({ &Src.Char.AsciiChar, 1 }, &Dst.Char);
}
Dst.Attributes = colors::ConsoleColorToFarColor(Src.Attributes);
};
}
}

static FAR_CHAR_INFO* AnsiVBufToUnicode(const oldfar::FarDialogItem &diA)
Expand Down Expand Up @@ -1341,10 +1342,10 @@ static void ConvertUnicodePanelInfoToAnsi(const PanelInfo* PIW, oldfar::PanelInf
PIA->SelectedItems = nullptr;
PIA->CurrentItem = static_cast<int>(PIW->CurrentItem);
PIA->TopPanelItem = static_cast<int>(PIW->TopPanelItem);
PIA->Visible = (PIW->Flags&PFLAGS_VISIBLE) ? 1 : 0;;
PIA->Focus = (PIW->Flags&PFLAGS_FOCUS) ? 1 : 0;;
PIA->Visible = (PIW->Flags&PFLAGS_VISIBLE)? 1 : 0;
PIA->Focus = (PIW->Flags&PFLAGS_FOCUS)? 1 : 0;
PIA->ViewMode = PIW->ViewMode;
PIA->ShortNames = (PIW->Flags&PFLAGS_ALTERNATIVENAMES) ? 1 : 0;;
PIA->ShortNames = (PIW->Flags&PFLAGS_ALTERNATIVENAMES)? 1 : 0;
PIA->SortMode = 0;

switch (PIW->SortMode)
Expand Down Expand Up @@ -3597,7 +3598,7 @@ static void WINAPI FarRestoreScreenA(HANDLE Screen) noexcept
CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr())
}

static int GetDirListGeneric(oldfar::PluginPanelItem*& PanelItems, int& ItemsSize, const std::function<int(PluginPanelItem*&, size_t&, size_t&)>& Getter)
static int GetDirListGeneric(oldfar::PluginPanelItem*& PanelItems, int& ItemsSize, function_ref<int(PluginPanelItem*&, size_t&, size_t&)> const Getter)
{
PanelItems = nullptr;
ItemsSize = 0;
Expand Down Expand Up @@ -5578,7 +5579,7 @@ class PluginA: public Plugin

};

#define CREATE_ITEMS(ItemsType) CreatePluginMenuItems(Src.ItemsType##Strings, Src.ItemsType##StringsNumber, PI.ItemsType);
#define CREATE_ITEMS(ItemsType) CreatePluginMenuItems(Src.ItemsType##Strings, Src.ItemsType##StringsNumber, PI.ItemsType)

CREATE_ITEMS(DiskMenu);
CREATE_ITEMS(PluginMenu);
Expand Down
4 changes: 3 additions & 1 deletion far/RegExp.cpp
Expand Up @@ -37,6 +37,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "string_utils.hpp"
#include "plugin.hpp"

#include "common/function_ref.hpp"

WARNING_DISABLE_GCC("-Wpragmas")
WARNING_DISABLE_GCC("-Wimplicit-fallthrough")

Expand Down Expand Up @@ -1801,7 +1803,7 @@ int RegExp::InnerMatch(const wchar_t* const start, const wchar_t* str, const wch

if (str<=strend)
{
const auto& MinSkip = [&](StateStackItem& st, const std::function<bool(const wchar_t*)>& cmp)
const auto& MinSkip = [&](StateStackItem& st, function_ref<bool(const wchar_t*)> const cmp)
{
int jj;
switch (std::next(op)->op)
Expand Down
8 changes: 8 additions & 0 deletions far/changelog
@@ -1,3 +1,11 @@
drkns 26.12.2018 11:22:00 +0000 - build 5345

1. std::function заменена на function_ref, где возможно. Что-то (где-то, когда-то) будет работать быстрее. Наверное.

2. Clang warnings.

3. Новая версия fmt.

drkns 23.12.2018 16:09:53 +0000 - build 5344

1. ColorDialog использует более очевидный цвет (чёрный) в качестве базы предпросмотра, если не указано иное.
Expand Down
8 changes: 8 additions & 0 deletions far/changelog_eng
Expand Up @@ -3,6 +3,14 @@ This file is a translation of the main russian changelog and is provided by volu
It might not always be as up to date as the main changelog.
=======================================================================================

drkns 26.12.2018 11:22:00 +0000 - build 5345

1. std::function replaced with function_ref where possible. Something (somewhere, sometime) will work faster. Probably.

2. Clang warnings.

3. New version of fmt.

drkns 23.12.2018 16:09:53 +0000 - build 5344

1. ColorDialog uses more obvious colour (black) as the base of the preview by default.
Expand Down
8 changes: 2 additions & 6 deletions far/cmdline.cpp
Expand Up @@ -893,7 +893,7 @@ void CommandLine::SetPromptSize(int NewSize)
PromptSize = NewSize? std::clamp(NewSize, 5, 95) : DEFAULT_CMDLINE_WIDTH;
}

static bool ProcessFarCommands(const string& Command, const std::function<void(bool)>& ConsoleActivatior)
static bool ProcessFarCommands(const string& Command, function_ref<void(bool)> const ConsoleActivatior)
{
if (equal_icase(Command, L"far:config"sv))
{
Expand Down Expand Up @@ -1056,7 +1056,7 @@ void CommandLine::ExecString(execute_info& Info)
IsUpdateNeeded = true;
}

bool CommandLine::ProcessOSCommands(string_view const CmdLine, const std::function<void(bool)>& ConsoleActivatior)
bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void(bool)> const ConsoleActivatior)
{
auto SetPanel = Global->CtrlObject->Cp()->ActivePanel();

Expand Down Expand Up @@ -1188,10 +1188,6 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, const std::functi
ppstack.push(PushDir);
os::env::set(L"FARDIRSTACK"sv, PushDir);
}
else
{
;
}

return true;
}
Expand Down
4 changes: 3 additions & 1 deletion far/cmdline.hpp
Expand Up @@ -38,6 +38,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "scrobj.hpp"
#include "editcontrol.hpp"

#include "common/function_ref.hpp"

struct execute_info
{
enum class wait_mode { no_wait, wait_idle, wait_finish };
Expand Down Expand Up @@ -90,7 +92,7 @@ class CommandLine:public SimpleScreenObject
private:
void DisplayObject() override;
size_t DrawPrompt();
bool ProcessOSCommands(string_view CmdLine, const std::function<void(bool)>& ConsoleActivatior);
bool ProcessOSCommands(string_view CmdLine, function_ref<void(bool)> ConsoleActivatior);
struct segment
{
string Text;
Expand Down
3 changes: 3 additions & 0 deletions far/common/enumerator.hpp
Expand Up @@ -135,6 +135,9 @@ class inline_enumerator: public enumerator<inline_enumerator<value_type, callabl
IMPLEMENTS_ENUMERATOR(inline_enumerator);

public:
NONCOPYABLE(inline_enumerator);
MOVABLE(inline_enumerator);

explicit inline_enumerator(callable&& Callable, finaliser&& Finaliser):
m_Callable(FWD(Callable)),
m_Finaliser(FWD(Finaliser))
Expand Down
78 changes: 78 additions & 0 deletions far/common/function_ref.hpp
@@ -0,0 +1,78 @@
#ifndef FUNCTION_REF_HPP_0B2E3AF4_AB0A_4C89_9FC1_1A92AC2699A4
#define FUNCTION_REF_HPP_0B2E3AF4_AB0A_4C89_9FC1_1A92AC2699A4
#pragma once

/*
function_ref.hpp
*/
/*
Copyright © 2018 Far Group
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "preprocessor.hpp"

template <typename callable_type>
class function_ref;

template <typename return_type, typename... args>
class function_ref<return_type(args...)> final
{
public:
template<typename callable_type, REQUIRES(!std::is_same_v<std::decay_t<callable_type>, function_ref>)>
function_ref(const callable_type& Callable) noexcept:
m_Ptr(&Callable)
{
// TODO: use initializer list after dropping VS2015
m_ErasedFn = [](const void* Ptr, args... Args) -> return_type
{
return std::invoke(*static_cast<const callable_type*>(Ptr), FWD(Args)...);
};
}

function_ref(std::nullptr_t) noexcept:
m_Ptr(),
m_ErasedFn()
{
}

decltype(auto) operator()(args... Args) const
{
return m_ErasedFn(m_Ptr, FWD(Args)...);
}

explicit operator bool() const noexcept
{
return m_Ptr != nullptr;
}

private:
using signature_type = return_type(const void*, args...);

const void* m_Ptr;
signature_type* m_ErasedFn;
};

#endif // FUNCTION_REF_HPP_0B2E3AF4_AB0A_4C89_9FC1_1A92AC2699A4
2 changes: 1 addition & 1 deletion far/common/multifunction.hpp
Expand Up @@ -120,7 +120,7 @@ class multifunction
{
public:
MOVABLE(multifunction);
COPY_AND_MOVE(multifunction, const multifunction&);
COPY_AND_MOVE(multifunction, const multifunction&)

multifunction() = default;

Expand Down
11 changes: 6 additions & 5 deletions far/config.cpp
Expand Up @@ -2862,11 +2862,12 @@ void Options::ShellOptions(bool LastCommand, const MOUSE_EVENT_RECORD *MouseEven

HMenuData MainMenu[]
{
{ msg(lng::MMenuLeftTitle), L"LeftRightMenu"sv, LeftMenu, true },
{ msg(lng::MMenuFilesTitle), L"FilesMenu"sv, FilesMenu },
{ msg(lng::MMenuCommandsTitle), L"CmdMenu"sv, CmdMenu },
{ msg(lng::MMenuOptionsTitle), L"OptMenu"sv, OptionsMenu },
{ msg(lng::MMenuRightTitle), L"LeftRightMenu"sv, RightMenu },
// TODO: remove make_range after dropping VS2015
{ msg(lng::MMenuLeftTitle), L"LeftRightMenu"sv, make_range(LeftMenu), true },
{ msg(lng::MMenuFilesTitle), L"FilesMenu"sv, make_range(FilesMenu) },
{ msg(lng::MMenuCommandsTitle), L"CmdMenu"sv, make_range(CmdMenu) },
{ msg(lng::MMenuOptionsTitle), L"OptMenu"sv, make_range(OptionsMenu) },
{ msg(lng::MMenuRightTitle), L"LeftRightMenu"sv, make_range(RightMenu) },
};
static int LastHItem=-1,LastVItem=0;
int HItem,VItem;
Expand Down
3 changes: 2 additions & 1 deletion far/configdb.cpp
Expand Up @@ -48,6 +48,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "platform.fs.hpp"

#include "common/bytes_view.hpp"
#include "common/function_ref.hpp"
#include "common/scope_exit.hpp"

#include "format.hpp"
Expand Down Expand Up @@ -1750,7 +1751,7 @@ class HistoryConfigCustom: public HistoryConfig, public sqlite_boilerplate
ExecuteStatement(stmtDel, id);
}

unsigned long long GetPrevImpl(const unsigned int TypeHistory, const string_view HistoryName, const unsigned long long id, string& Name, const std::function<unsigned long long()>& Fallback) const
unsigned long long GetPrevImpl(const unsigned int TypeHistory, const string_view HistoryName, const unsigned long long id, string& Name, function_ref<unsigned long long()> const Fallback) const
{
WaitAllAsync();
Name.clear();
Expand Down

0 comments on commit c261b6a

Please sign in to comment.