[Libreoffice-commits] core.git: sc/inc sc/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 30 16:54:31 UTC 2019


 sc/inc/address.hxx              |   16 +++++-----------
 sc/source/core/data/bcaslot.cxx |   25 ++++++++++---------------
 2 files changed, 15 insertions(+), 26 deletions(-)

New commits:
commit c561d7289b23507f810f8a4fc9c16a314f7fb0a8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Sep 30 09:39:01 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Sep 30 18:53:32 2019 +0200

    reduce number of calc column constants slightly
    
    and add some comments
    
    Change-Id: If71a3dff151fea249337668cf25b9c91d200d401
    Reviewed-on: https://gerrit.libreoffice.org/79829
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index df26f12c1408..c420da83120c 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -59,18 +59,12 @@ const SCTAB    SCTAB_MAX    = ::std::numeric_limits<SCTAB>::max();
 const SCCOLROW SCCOLROW_MAX = ::std::numeric_limits<SCCOLROW>::max();
 const SCSIZE   SCSIZE_MAX   = ::std::numeric_limits<SCSIZE>::max();
 
-// The maximum values. Defines are needed for preprocessor checks, for example
-// in bcaslot.cxx, otherwise type safe constants are preferred.
-#define MAXROWCOUNT_DEFINE 1048576
-#define MAXCOLCOUNT_DEFINE 1024
-
 // Count values
-const SCROW       MAXROWCOUNT    = MAXROWCOUNT_DEFINE;
-const SCCOL       MAXCOLCOUNT    = MAXCOLCOUNT_DEFINE;
-const SCCOL       INITIALCOLCOUNT = 64;
+const SCROW       MAXROWCOUNT    = 1048576;
+const SCCOL       MAXCOLCOUNT    = 1024;
+const SCCOL       INITIALCOLCOUNT = 64; // initial number of columns we allocate memory for
 /// limiting to 10000 for now, problem with 32 bit builds for now
 const SCTAB       MAXTABCOUNT    = 10000;
-const SCCOLROW    MAXCOLROWCOUNT = MAXROWCOUNT;
 // Maximum values
 const SCROW       MAXROW         = MAXROWCOUNT - 1;
 const SCCOL       MAXCOL         = MAXCOLCOUNT - 1;
@@ -87,11 +81,11 @@ const SCTAB       MININITTAB = 1;
 // Special values
 const SCTAB SC_TAB_APPEND     = SCTAB_MAX;
 const SCTAB TABLEID_DOC       = SCTAB_MAX;  // entire document, e.g. protect
-const SCROW SCROWS32K         = 32000;
+const SCROW SCROWS32K         = 32000; // for fuzzing
 const SCCOL SCCOL_REPEAT_NONE = SCCOL_MAX;
 const SCROW SCROW_REPEAT_NONE = SCROW_MAX;
 
-#define MAXROW_30   8191
+const SCROW MAXROW_30         = 8191;
 
 [[nodiscard]] inline bool ValidCol( SCCOL nCol )
 {
diff --git a/sc/source/core/data/bcaslot.cxx b/sc/source/core/data/bcaslot.cxx
index 674dca338c82..0e56dc3f3600 100644
--- a/sc/source/core/data/bcaslot.cxx
+++ b/sc/source/core/data/bcaslot.cxx
@@ -37,26 +37,21 @@
 
 // Number of slots per dimension
 // must be integer divisors of MAXCOLCOUNT respectively MAXROWCOUNT
-#define BCA_SLOTS_COL ((MAXCOLCOUNT_DEFINE) / 16)
-#define BCA_SLICE 128
-#define BCA_SLOTS_ROW ((MAXROWCOUNT_DEFINE) / BCA_SLICE)
-#define BCA_SLOT_COLS ((MAXCOLCOUNT_DEFINE) / BCA_SLOTS_COL)
-#define BCA_SLOT_ROWS ((MAXROWCOUNT_DEFINE) / BCA_SLOTS_ROW)
+constexpr SCCOL BCA_SLOTS_COL  = MAXCOLCOUNT / 16;
+constexpr SCROW BCA_SLICE = 128;
+constexpr SCROW BCA_SLOTS_ROW  = MAXROWCOUNT / BCA_SLICE;
+constexpr SCCOL BCA_SLOT_COLS  = MAXCOLCOUNT / BCA_SLOTS_COL;
+constexpr SCROW BCA_SLOT_ROWS  = MAXROWCOUNT / BCA_SLOTS_ROW;
 // multiple?
-#if (BCA_SLOT_COLS * BCA_SLOTS_COL) != (MAXCOLCOUNT_DEFINE)
-#error bad BCA_SLOTS_COL value!
-#endif
-#if (BCA_SLOT_ROWS * BCA_SLOTS_ROW) != (MAXROWCOUNT_DEFINE)
-#error bad BCA_SLOTS_ROW value!
-#endif
+static_assert((BCA_SLOT_COLS * BCA_SLOTS_COL) == MAXCOLCOUNT && "bad BCA_SLOTS_COL value");
+static_assert((BCA_SLOT_ROWS * BCA_SLOTS_ROW) == MAXROWCOUNT && "bad BCA_SLOTS_ROW value");
+
 // size of slot array if linear
-#define BCA_SLOTS_DEFINE (BCA_SLOTS_COL * BCA_SLOTS_ROW)
+constexpr int BCA_SLOTS  = BCA_SLOTS_COL * BCA_SLOTS_ROW;
 // Arbitrary 2**31/8, assuming size_t can hold at least 2^31 values and
 // sizeof_ptr is at most 8 bytes. You'd probably doom your machine's memory
 // anyway, once you reached these values...
-#if BCA_SLOTS_DEFINE > 268435456
-#error BCA_SLOTS_DEFINE DOOMed!
-#endif
+static_assert(BCA_SLOTS <= 268435456 && "DOOMed");
 
 struct ScSlotData
 {


More information about the Libreoffice-commits mailing list