[Libreoffice-commits] core.git: include/tools tools/source vcl/source
include/tools/fract.hxx|3 +++ tools/source/generic/fract.cxx | 40 vcl/source/outdev/map.cxx | 32 +--- 3 files changed, 44 insertions(+), 31 deletions(-) New commits: commit 551e5943d4bec10c31077f38ccf5d8149c05265c Author: Noel Grandin AuthorDate: Thu Oct 27 08:48:25 2022 +0200 Commit: Noel Grandin CommitDate: Thu Oct 27 10:58:04 2022 +0200 tdf#123419 optimise ImplMakeFraction which is very hot here. Push it down into Fraction, where we can skip the construction of boost::rational intermediate values Change-Id: I7e5f18456a252a159d3a50e9297168e5ba9e1588 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141894 Tested-by: Jenkins Reviewed-by: Noel Grandin diff --git a/include/tools/fract.hxx b/include/tools/fract.hxx index c844f8eed619..e1305ca8a8fd 100644 --- a/include/tools/fract.hxx +++ b/include/tools/fract.hxx @@ -72,6 +72,9 @@ public: voidReduceInaccurate( unsigned nSignificantBits ); +/// Multiply the two fractions represented here and reduce inaccuracy to 32-bits, used by vcl +static Fraction MakeFraction(tools::Long nN1, tools::Long nN2, tools::Long nD1, tools::Long nD2); + // Compute value usable as hash. size_t GetHashValue() const; diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx index 7f2ffba1003d..b6ae743764df 100644 --- a/tools/source/generic/fract.cxx +++ b/tools/source/generic/fract.cxx @@ -483,4 +483,44 @@ size_t Fraction::GetHashValue() const return hash; } +Fraction Fraction::MakeFraction( tools::Long nN1, tools::Long nN2, tools::Long nD1, tools::Long nD2 ) +{ +if( nD1 == 0 || nD2 == 0 ) //under these bad circumstances the following while loop will be endless +{ +SAL_WARN("tools.fraction", "Invalid parameter for ImplMakeFraction"); +return Fraction( 1, 1 ); +} + +tools::Long i = 1; + +if ( nN1 < 0 ) { i = -i; nN1 = -nN1; } +if ( nN2 < 0 ) { i = -i; nN2 = -nN2; } +if ( nD1 < 0 ) { i = -i; nD1 = -nD1; } +if ( nD2 < 0 ) { i = -i; nD2 = -nD2; } +// all positive; i sign + +boost::rational a = toRational(i*nN1, nD1); +boost::rational b = toRational(nN2, nD2); +bool bFail = checked_multiply_by(a, b); + + +while ( bFail ) { +if ( nN1 > nN2 ) +nN1 = (nN1 + 1) / 2; +else +nN2 = (nN2 + 1) / 2; +if ( nD1 > nD2 ) +nD1 = (nD1 + 1) / 2; +else +nD2 = (nD2 + 1) / 2; + +a = toRational(i*nN1, nD1); +b = toRational(nN2, nD2); +bFail = checked_multiply_by(a, b); +} + +rational_ReduceInaccurate(a, /*nSignificantBits*/32); +return Fraction(a.numerator(), a.denominator()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index 2c3801bf9e84..02221c345862 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -44,37 +44,7 @@ ctor fraction once); we could also do this with BigInts static Fraction ImplMakeFraction( tools::Long nN1, tools::Long nN2, tools::Long nD1, tools::Long nD2 ) { -if( nD1 == 0 || nD2 == 0 ) //under these bad circumstances the following while loop will be endless -{ -SAL_WARN("vcl.gdi", "Invalid parameter for ImplMakeFraction"); -return Fraction( 1, 1 ); -} - -tools::Long i = 1; - -if ( nN1 < 0 ) { i = -i; nN1 = -nN1; } -if ( nN2 < 0 ) { i = -i; nN2 = -nN2; } -if ( nD1 < 0 ) { i = -i; nD1 = -nD1; } -if ( nD2 < 0 ) { i = -i; nD2 = -nD2; } -// all positive; i sign - -Fraction aF = Fraction( i*nN1, nD1 ) * Fraction( nN2, nD2 ); - -while ( !aF.IsValid() ) { -if ( nN1 > nN2 ) -nN1 = (nN1 + 1) / 2; -else -nN2 = (nN2 + 1) / 2; -if ( nD1 > nD2 ) -nD1 = (nD1 + 1) / 2; -else -nD2 = (nD2 + 1) / 2; - -aF = Fraction( i*nN1, nD1 ) * Fraction( nN2, nD2 ); -} - -aF.ReduceInaccurate(32); -return aF; +return Fraction::MakeFraction(nN1, nN2, nD1, nD2); } static auto setMapRes(ImplMapRes& rMapRes, const o3tl::Length eUnit)
[Libreoffice-commits] core.git: include/tools tools/source vcl/source
include/tools/json_writer.hxx |3 ++ tools/source/misc/json_writer.cxx | 49 +++--- vcl/source/control/combobox.cxx | 18 +++-- vcl/source/control/listbox.cxx| 10 +++ vcl/source/window/toolbox2.cxx|4 +-- vcl/source/window/window.cxx |4 +-- 6 files changed, 56 insertions(+), 32 deletions(-) New commits: commit 7fc2fe5c612f95b9624f49b5fdea2d3c8c94caf1 Author: Szymon Kłos AuthorDate: Tue Nov 24 15:03:27 2020 +0100 Commit: Szymon Kłos CommitDate: Thu Dec 3 08:45:24 2020 +0100 jsdialog: fix arrays in JsonWriter output Change-Id: I5638b1b02afcdd57b16b60d83d3d15da45866060 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107066 Tested-by: Jenkins Reviewed-by: Szymon Kłos diff --git a/include/tools/json_writer.hxx b/include/tools/json_writer.hxx index 10e1a3a7aafc..440fedccf45e 100644 --- a/include/tools/json_writer.hxx +++ b/include/tools/json_writer.hxx @@ -64,6 +64,8 @@ public: void put(const char* pPropName, bool); void put(const char* pPropName, double); +void putSimpleValue(const OUString& rPropValue); + /// This assumes that this data belongs at this point in the stream, and is valid, and properly encoded void putRaw(const rtl::OStringBuffer&); @@ -82,6 +84,7 @@ private: void endStruct(); void addCommaBeforeField(); void reallocBuffer(int noMoreBytesRequired); +void writeEscapedOUString(const OUString& rPropVal); // this part inline to speed up the fast path inline void ensureSpace(int noMoreBytesRequired) diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx index 1ccee8569480..a0e0280b840e 100644 --- a/tools/source/misc/json_writer.cxx +++ b/tools/source/misc/json_writer.cxx @@ -120,21 +120,8 @@ void JsonWriter::endStruct() mbFirstFieldInNode = false; } -void JsonWriter::put(const char* pPropName, const OUString& rPropVal) +void JsonWriter::writeEscapedOUString(const OUString& rPropVal) { -auto nPropNameLength = strlen(pPropName); -auto nWorstCasePropValLength = rPropVal.getLength() * 2; -ensureSpace(nPropNameLength + nWorstCasePropValLength + 8); - -addCommaBeforeField(); - -*mPos = '"'; -++mPos; -memcpy(mPos, pPropName, nPropNameLength); -mPos += nPropNameLength; -memcpy(mPos, "\": \"", 4); -mPos += 4; - // Convert from UTF-16 to UTF-8 and perform escaping for (int i = 0; i < rPropVal.getLength(); ++i) { @@ -175,6 +162,24 @@ void JsonWriter::put(const char* pPropName, const OUString& rPropVal) ++mPos; } } +} + +void JsonWriter::put(const char* pPropName, const OUString& rPropVal) +{ +auto nPropNameLength = strlen(pPropName); +auto nWorstCasePropValLength = rPropVal.getLength() * 2; +ensureSpace(nPropNameLength + nWorstCasePropValLength + 8); + +addCommaBeforeField(); + +*mPos = '"'; +++mPos; +memcpy(mPos, pPropName, nPropNameLength); +mPos += nPropNameLength; +memcpy(mPos, "\": \"", 4); +mPos += 4; + +writeEscapedOUString(rPropVal); *mPos = '"'; ++mPos; @@ -332,6 +337,22 @@ void JsonWriter::put(const char* pPropName, bool nPropVal) mPos += strlen(pVal); } +void JsonWriter::putSimpleValue(const OUString& rPropVal) +{ +auto nWorstCasePropValLength = rPropVal.getLength() * 2; +ensureSpace(nWorstCasePropValLength + 4); + +addCommaBeforeField(); + +*mPos = '"'; +++mPos; + +writeEscapedOUString(rPropVal); + +*mPos = '"'; +++mPos; +} + void JsonWriter::putRaw(const rtl::OStringBuffer& rRawBuf) { ensureSpace(rRawBuf.getLength() + 2); diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx index 666feb9e3216..89bf43b075f7 100644 --- a/vcl/source/control/combobox.cxx +++ b/vcl/source/control/combobox.cxx @@ -1544,18 +1544,20 @@ void ComboBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { Control::DumpAsPropertyTree(rJsonWriter); -auto entriesNode = rJsonWriter.startNode("entries"); -for (int i = 0; i < GetEntryCount(); ++i) { -auto entryNode = rJsonWriter.startNode(""); -rJsonWriter.put("", GetEntry(i)); +auto entriesNode = rJsonWriter.startArray("entries"); +for (int i = 0; i < GetEntryCount(); ++i) +{ +rJsonWriter.putSimpleValue(GetEntry(i)); +} } -auto selectedNode = rJsonWriter.startNode("selectedEntries"); -for (int i = 0; i < GetSelectedEntryCount(); ++i) { -auto entryNode = rJsonWriter.startNode(""); -rJsonWriter.put("", GetSelectedEntryPos(i)); +auto selectedNode = rJsonWriter.startArray("selectedEntries"); +for (int i = 0; i < GetSelectedEntryCount(); ++i) +{ + rJsonWriter.putSimpleValue(OUString::number(GetSelectedEntryPos(i))); +} } rJsonWriter.put("selectedCount", GetSelectedEntryCount()); diff --
[Libreoffice-commits] core.git: include/tools tools/source vcl/source
include/tools/gen.hxx |2 +- tools/source/generic/gen.cxx |6 ++ vcl/source/gdi/mtfxmldump.cxx |5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) New commits: commit 1ce1c26dd98e6477139e08d1ebe89fa950ff5fb0 Author: Noel Grandin AuthorDate: Fri Jul 12 12:06:41 2019 +0200 Commit: Noel Grandin CommitDate: Fri Jul 12 17:04:02 2019 +0200 make tools::Rectangle::Right return Left when empty I tried making this assert, but there are just too many places where we pass around empty rectangles, so rather just return the value of nLeft, in a similar fashion to methods like Rectangle::TopLeft Change-Id: I3377071ecae26f13e895ae411cd269f0bdbe0ef6 Reviewed-on: https://gerrit.libreoffice.org/75486 Tested-by: Jenkins Reviewed-by: Noel Grandin diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx index 54a438bfa161..dd0514396567 100644 --- a/include/tools/gen.hxx +++ b/include/tools/gen.hxx @@ -386,7 +386,7 @@ public: Rectangle( const Point& rLT, const Size& rSize ); longLeft() const{ return nLeft; } -longRight() const { return nRight; } +longRight() const; longTop() const { return nTop;} longBottom() const { return nBottom; } diff --git a/tools/source/generic/gen.cxx b/tools/source/generic/gen.cxx index fc927f50e41e..459687dc961a 100644 --- a/tools/source/generic/gen.cxx +++ b/tools/source/generic/gen.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -291,4 +292,9 @@ void tools::Rectangle::setY( long y ) nTop = y; } +long tools::Rectangle::Right() const +{ +return nRight == RECT_EMPTY ? nLeft : nRight; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx index 8c168a89d4c4..c679b08e86e6 100644 --- a/vcl/source/gdi/mtfxmldump.cxx +++ b/vcl/source/gdi/mtfxmldump.cxx @@ -459,8 +459,9 @@ void writeRectangle(tools::XmlWriter& rWriter, tools::Rectangle const& rRectangl { rWriter.attribute("left", rRectangle.Left()); rWriter.attribute("top", rRectangle.Top()); -rWriter.attribute("right", rRectangle.Right()); -rWriter.attribute("bottom", rRectangle.Bottom()); +// FIXME what should we write for empty? +rWriter.attribute("right", rRectangle.IsWidthEmpty() ? -32767 : rRectangle.Right()); +rWriter.attribute("bottom", rRectangle.IsHeightEmpty() ? -32767 : rRectangle.Bottom()); } void writeLineInfo(tools::XmlWriter& rWriter, LineInfo const& rLineInfo) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: include/tools tools/source vcl/source
include/tools/debug.hxx |4 ++-- tools/source/debug/debug.cxx |2 +- vcl/source/app/svmain.cxx|2 +- 3 files changed, 4 insertions(+), 4 deletions(-) New commits: commit 9cceba9a928cf3b3447f293020be2fe76c035ed5 Author: Noel Grandin AuthorDate: Fri Jul 27 10:13:19 2018 +0200 Commit: Noel Grandin CommitDate: Mon Jul 30 08:58:59 2018 +0200 make DBG_TESTSOLARMUTEX available in assert builds where our QA people are more likely to trigger it Change-Id: I4ce7c8c72e7e21f2296c0f9cc9f019aaef32ed0b Reviewed-on: https://gerrit.libreoffice.org/58170 Tested-by: Jenkins Reviewed-by: Noel Grandin diff --git a/include/tools/debug.hxx b/include/tools/debug.hxx index 3f5d68a670e4..3fa2d5f9460a 100644 --- a/include/tools/debug.hxx +++ b/include/tools/debug.hxx @@ -35,7 +35,8 @@ standard assert. */ -#ifdef DBG_UTIL +#ifndef NDEBUG +// we want the solar mutex checking to be enabled in the assert-enabled builds that the QA people use typedef void (*DbgTestSolarMutexProc)(); @@ -49,7 +50,6 @@ do \ } while(false) #else -// NO DBG_UTIL #define DBG_TESTSOLARMUTEX() ((void)0) diff --git a/tools/source/debug/debug.cxx b/tools/source/debug/debug.cxx index 220d577be52d..9f32eab3267c 100644 --- a/tools/source/debug/debug.cxx +++ b/tools/source/debug/debug.cxx @@ -45,7 +45,7 @@ #include #endif -#ifdef DBG_UTIL +#ifndef NDEBUG struct DebugData { diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx index c2de4819b541..471abc951ffc 100644 --- a/vcl/source/app/svmain.cxx +++ b/vcl/source/app/svmain.cxx @@ -367,7 +367,7 @@ bool InitVCL() // Set exception handler pExceptionHandler = osl_addSignalHandler(VCLExceptionSignal_impl, nullptr); -#ifdef DBG_UTIL +#ifndef NDEBUG DbgGUIInitSolarMutexCheck(); #endif ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: include/tools tools/source vcl/source
include/tools/resid.hxx| 35 ++- tools/source/rc/rc.cxx | 11 +-- tools/source/rc/resmgr.cxx |4 ++-- vcl/source/window/resource.cxx |1 - 4 files changed, 17 insertions(+), 34 deletions(-) New commits: commit f9aee52eb56c69373c98ced5aff2128ea8c26f1d Author: Noel Grandin Date: Sun Apr 10 14:44:15 2016 +0200 give tools::ResId a shave and a haircut m_nRT2 and m_nWinBits fields are not in use anymore, at least as far back as 2013, when the heading files were moved around Change-Id: Ie3299a576450803332aeab72d5c0e68227e2 Reviewed-on: https://gerrit.libreoffice.org/23960 Reviewed-by: Noel Grandin Tested-by: Noel Grandin diff --git a/include/tools/resid.hxx b/include/tools/resid.hxx index aa47075..29452c6 100644 --- a/include/tools/resid.hxx +++ b/include/tools/resid.hxx @@ -47,12 +47,10 @@ class ResId mutable sal_uInt32 m_nResId; // Resource Identifier mutable RESOURCE_TYPE m_nRT; // type for loading (mutable to be set later) mutable ResMgr *m_pResMgr; // load from this ResMgr (mutable for setting on demand) -mutable RESOURCE_TYPE m_nRT2;// type for loading (supersedes m_nRT) -mutable sal_uInt32 m_nWinBits;// container for original style bits on a window in a resource void ImplInit( sal_uInt32 nId, ResMgr& rMgr, RSHEADER_TYPE* pRes ) { -m_pResource = pRes; m_nResId = nId; m_nRT = RSC_NOTYPE; m_pResMgr = &rMgr; m_nRT2 = RSC_NOTYPE; m_nWinBits = 0; +m_pResource = pRes; m_nResId = nId; m_nRT = RSC_NOTYPE; m_pResMgr = &rMgr; OSL_ENSURE( m_pResMgr != nullptr, "ResId without ResMgr created" ); } @@ -66,8 +64,6 @@ public: ImplInit( nId, rMgr, nullptr ); } -void SetWinBits( sal_uInt32 nBits ) const { m_nWinBits = nBits; } - RESOURCE_TYPE GetRT() const { return m_nRT; } /** Set the type if not already set. Ask for type with GetRT() @@ -81,22 +77,12 @@ public: @see ResId::GetRT2(), ResId::GetRT() */ -const ResId & SetRT( RESOURCE_TYPE nType ) const -{ -if( RSC_NOTYPE == m_nRT ) -m_nRT = nType; -return *this; -} - -/** Get the effective type (m_nRT2 or m_nRT1) - -A second resource type is used to supersede settings -of the base class ( e.g. Window ) -*/ -RESOURCE_TYPE GetRT2() const -{ -return (RSC_NOTYPE == m_nRT2) ? m_nRT : m_nRT2; -} + const ResId & SetRT( RESOURCE_TYPE nType ) const + { + if( RSC_NOTYPE == m_nRT ) + m_nRT = nType; + return *this; + } ResMgr *GetResMgr() const { return m_pResMgr; } voidSetResMgr( ResMgr * pMgr ) const @@ -114,11 +100,10 @@ public: return *this; } -boolIsAutoRelease() const -{ return !(m_nResId & RSC_DONTRELEASE); } +boolIsAutoRelease() const { return !(m_nResId & RSC_DONTRELEASE); } -sal_uInt32 GetId()const { return m_nResId & ~RSC_DONTRELEASE; } -RSHEADER_TYPE* GetpResource() const { return m_pResource; } +sal_uInt32 GetId() const { return m_nResId & ~RSC_DONTRELEASE; } +RSHEADER_TYPE* GetpResource() const { return m_pResource; } TOOLS_DLLPUBLIC OUString toString() const; TOOLS_DLLPUBLIC operator OUString() const { return toString(); } diff --git a/tools/source/rc/rc.cxx b/tools/source/rc/rc.cxx index de16eaa..262f07a 100644 --- a/tools/source/rc/rc.cxx +++ b/tools/source/rc/rc.cxx @@ -18,7 +18,7 @@ */ #include -#include +#include #include #include #include @@ -42,6 +42,7 @@ void Resource::GetRes( const ResId& rResId ) OUString ResId::toString() const { SetRT( RSC_STRING ); + ResMgr* pResMgr = GetResMgr(); if ( !pResMgr || !pResMgr->GetResource( *this ) ) @@ -49,11 +50,9 @@ OUString ResId::toString() const OUString sRet; #if OSL_DEBUG_LEVEL > 0 -sRet = OUStringBuffer(). -append("(GetId())). -append(" not found>"). -makeStringAndClear(); +sRet = "(GetId())) ++ " not found>"; #endif if( pResMgr ) diff --git a/tools/source/rc/resmgr.cxx b/tools/source/rc/resmgr.cxx index 8cccee4..668b414 100644 --- a/tools/source/rc/resmgr.cxx +++ b/tools/source/rc/resmgr.cxx @@ -913,7 +913,7 @@ bool ResMgr::IsAvailable( const ResId& rId, const Resource* pResObj ) const boolbAvailable = false; RSHEADER_TYPE* pClassRes = rId.GetpResource(); -RESOURCE_TYPE nRT = rId.GetRT2(); +RESOURCE_TYPE nRT = rId.GetRT(); sal_uInt32 nId = rId.GetId(); const ResMgr* pMgr = rId.GetResMgr(); @@ -978,7 +978,7 @@ bool ResMgr::GetResource( const ResId& rId, const Resource* pResObj ) } RSHEADER_TYPE* pClassRes = rId.GetpResource(); -RESOURCE_TYPE nRT = rId.GetRT2(); +RESO