Skip to content

Commit

Permalink
Merge pull request #3867 from moneymanagerex/master
Browse files Browse the repository at this point in the history
fix(#3865): speedup
  • Loading branch information
vomikan committed Sep 18, 2021
2 parents aff712a + 693c3bc commit 3083b02
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/currencydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void mmCurrencyDialog::OnTextChanged(wxCommandEvent& WXUNUSED(event))
m_currency->SFX_SYMBOL = sfxTx_->GetValue();
m_currency->DECIMAL_POINT = decTx_->GetValue();
m_currency->GROUP_SEPARATOR = grpTx_->GetValue();
m_currency->SCALE = static_cast<int>(pow(10, scale));
m_currency->SCALE = pow10(scale);
m_currency->CURRENCY_SYMBOL = m_currencySymbol->GetValue().Trim();
m_currency->CURRENCYNAME = m_currencyName->GetValue();

Expand Down
2 changes: 1 addition & 1 deletion src/mmcustomdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool mmCustomData::FillCustomFields(wxBoxSizer* box_sizer)
int DigitScale = Model_CustomField::getDigitScale(field.PROPERTIES);
wxSpinCtrlDouble* CustomDecimal = new wxSpinCtrlDouble(scrolled_window, controlID
, wxEmptyString, wxDefaultPosition, wxDefaultSize
, wxSP_ARROW_KEYS, -2147483647, 2147483647, value, 1 / pow(10, DigitScale));
, wxSP_ARROW_KEYS, -2147483647, 2147483647, value, 1 / pow10(DigitScale));
CustomDecimal->SetDigits(DigitScale);
mmToolTip(CustomDecimal, Model_CustomField::getTooltip(field.PROPERTIES));
grid_sizer_custom->Add(CustomDecimal, g_flagsExpand);
Expand Down
5 changes: 3 additions & 2 deletions src/mmhomepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ const wxString htmlWidgetIncomeVsExpenses::getHTMLText()
if (scaleStepWidth <= 1.0)
scaleStepWidth = 1.0;
else {
double s = (pow(10, ceil(log10(scaleStepWidth)) - 1.0));
if (s > 0) scaleStepWidth = ceil(scaleStepWidth / s)*s;
double s = pow10(ceil(log10(scaleStepWidth)) - 1.0);
if (s > 0)
scaleStepWidth = ceil(scaleStepWidth / s)*s;
}

StringBuffer json_buffer;
Expand Down
7 changes: 4 additions & 3 deletions src/model/Model_Currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Model_Checking.h"
#include "Model_Stock.h"
#include "option.h"
#include "util.h"

#include <fmt/core.h>
#include <fmt/locale.h>
Expand Down Expand Up @@ -221,19 +222,19 @@ const wxString Model_Currency::toString(double value, const Data* currency, int
precision = log10(currency ? currency->SCALE : GetBaseCurrency()->SCALE);
}

int k = pow(10, precision);
int k = pow10(precision);
long double v = value * k;
v = round(v) / k;

wxString s;
if (defaultLocaleSupport == "Y")
{
s = fmt::format((use_locale == "Y" ? std::locale(locale.c_str()) : std::locale("en_US"))
, "{:L}", static_cast<unsigned long long>(fabs(v) + 5 / (pow(10, precision + 1))));
, "{:L}", static_cast<unsigned long long>(fabs(v) + 5 / (pow10(precision + 1))));
}
else {
//In case if no en_US supported don't use any one
s = fmt::format("{:d}", static_cast<unsigned long long>(fabs(v) + 5 / (pow(10, precision + 1))));
s = fmt::format("{:d}", static_cast<unsigned long long>(fabs(v) + 5 / (pow10(precision + 1))));
}

if (precision > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/reports/htmlbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void mmHTMLBuilder::endTableCell()
void mmHTMLBuilder::addChart(const GraphData& gd)
{
int precision = Model_Currency::precision(Model_Currency::GetBaseCurrency());
int round = pow(10, precision);
int round = pow10(precision);
wxString htmlChart, htmlPieData;
wxString divid = wxString::Format("apex%i", rand()); // Generate unique identifier for each graph

Expand Down
20 changes: 19 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,4 +1546,22 @@ const wxColor* bestFontColour(wxColour background)
void mmToolTip(wxWindow* widget, wxString tip)
{
if (Option::instance().getShowToolTips()) widget->SetToolTip(tip);
}
}

int pow10(int y)
{
switch (y)
{
case 0: return 1;
case 1: return 10;
case 2: return 100;
case 3: return 1000;
case 4: return 10000;
case 5: return 100000;
case 6: return 1000000;
case 7: return 10000000;
case 8: return 100000000;
case 9: return 1000000000;
default: return 10;
}
}
3 changes: 3 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,6 @@ const wxColor* bestFontColour(wxColour background);
wxImageList* createImageList();

void mmToolTip(wxWindow* widget, wxString tip);

//fast alternative for pow(10, y)
int pow10(int y);

0 comments on commit 3083b02

Please sign in to comment.