Skip to content

Commit

Permalink
convert JArray ctor back to minSize, to avoid upgrade confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
jafl committed Dec 10, 2024
1 parent fbc98b4 commit c06cee5
Show file tree
Hide file tree
Showing 33 changed files with 87 additions and 81 deletions.
7 changes: 4 additions & 3 deletions libj2dplot/code/J2DPlotFunctionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <jx-af/jcore/JMinMax.h>
#include <jx-af/jcore/jAssert.h>

const JSize kDefSampleCount = 100; // # of points for approximating y range

/*********************************************************************************
Constructor
Expand All @@ -31,7 +33,7 @@ J2DPlotFunctionBase::J2DPlotFunctionBase
itsXMin = JMin(xMin, xMax);
itsXMax = JMax(xMin, xMax);

itsValues = jnew JArray<Point>(7);
itsValues = jnew JArray<Point>(kDefSampleCount);
ListenTo(itsPlot);
}

Expand Down Expand Up @@ -109,8 +111,7 @@ J2DPlotFunctionBase::GetYRange
const
{
const JSize pointCount = itsPlot->GetSmoothSteps();
JArray<Point> list;
list.SetMinSize(pointCount);
JArray<Point> list(pointCount);
EvaluateFunction(xMin, xMax, xLinear, pointCount, &list);

*yMin = *yMax = 0.0;
Expand Down
10 changes: 6 additions & 4 deletions libj2dplot/code/J2DVectorData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <jx-af/jcore/JMinMax.h>
#include <jx-af/jcore/jAssert.h>

const JSize kDefSampleCount = 100;

/*********************************************************************************
Constructor function (static)
Expand Down Expand Up @@ -69,10 +71,10 @@ J2DVectorData::J2DVectorData()
{
J2DVectorDataX();

itsXData = jnew JArray<JFloat>(7);
itsYData = jnew JArray<JFloat>(7);
itsVXData = jnew JArray<JFloat>(7);
itsVYData = jnew JArray<JFloat>(7);
itsXData = jnew JArray<JFloat>(kDefSampleCount);
itsYData = jnew JArray<JFloat>(kDefSampleCount);
itsVXData = jnew JArray<JFloat>(kDefSampleCount);
itsVYData = jnew JArray<JFloat>(kDefSampleCount);

itsIsListeningFlag = false;
}
Expand Down
2 changes: 1 addition & 1 deletion libj2dplot/code/JX2DCurveNameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ JX2DCurveNameList::JX2DCurveNameList

const JSize count = curveInfo.GetItemCount();

itsNameList = jnew JPtrArray<JString>(JPtrArrayT::kForgetAll);
itsNameList = jnew JPtrArray<JString>(JPtrArrayT::kForgetAll, count);

AppendRows(count);
for (JIndex i=1; i<=count; i++)
Expand Down
3 changes: 2 additions & 1 deletion libjcore/code/JAliasArray.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ JAliasArray<T>::JAliasArray
{
assert( itsData != nullptr );

itsIndexArray = jnew JArray<JIndex>(data->GetMinLgSize());
itsIndexArray = jnew JArray<JIndex>;
itsIndexArray->SetMinLgSize(data->GetMinLgSize());
itsIndexArray->SetSortOrder(order);

SetCompareFunction(compareFn);
Expand Down
2 changes: 1 addition & 1 deletion libjcore/code/JArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class JArray : public JList<T>
{
public:

JArray(const JSize minLgSize = 0);
JArray(const JSize minSize = 0);
JArray(const JArray<T>& source);
JArray(JArray<T>&& dyingSource) noexcept;

Expand Down
11 changes: 5 additions & 6 deletions libjcore/code/JArray.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "JArray.h"
#include "JMinMax.h"
#include "jMath.h"
#include <bit>
#include <string.h> // for memcpy,memmove
#include <stdlib.h> // for qsort
// we are included by jAssert.h
Expand All @@ -38,7 +39,7 @@ inline JSize jArrayLgToSize(const JSize lgSize)

inline JSize jArraySizeToLg(const JSize count)
{
return JLCeil(std::log2(count+1));
return std::bit_width(count);
}

/******************************************************************************
Expand All @@ -49,15 +50,13 @@ inline JSize jArraySizeToLg(const JSize count)
template <class T>
JArray<T>::JArray
(
const JSize minLgSize
const JSize minSize
)
:
JList<T>(),
itsLgSize(JMax(kJArrayDefaultMinLgSize, minLgSize)),
itsLgSize(JMax(kJArrayDefaultMinLgSize, jArraySizeToLg(minSize))),
itsMinLgSize(itsLgSize)
{
assert( itsMinLgSize < 12 );

itsItems = jnew T [ jArrayLgToSize(itsLgSize) ];
}

Expand Down Expand Up @@ -275,7 +274,7 @@ JArray<T>::CreateItem
{
assert( index > 0 );

const JSize newLgSize = JMax(itsMinLgSize, jArraySizeToLg(this->GetItemCount()));
const JSize newLgSize = JMax(itsMinLgSize, jArraySizeToLg(this->GetItemCount() + 1));
if (newLgSize > itsLgSize)
{
ResizeMemoryAllocation(newLgSize);
Expand Down
2 changes: 1 addition & 1 deletion libjcore/code/JAsynchDataReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JAsynchDataReceiverT

enum
{
kDefaultLgBufferSize = 16
kDefaultBufferSize = 65536
};

public:
Expand Down
6 changes: 3 additions & 3 deletions libjcore/code/JAsynchDataReceiver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template <ACE_PEER_STREAM_1>
JAsynchDataReceiver<ACE_PEER_STREAM_2>::JAsynchDataReceiver()
:
ACE_Svc_Handler<ACE_PEER_STREAM_2,ACE_SYNCH>(),
itsByteBuffer(JAsynchDataReceiverT::kDefaultLgBufferSize)
itsByteBuffer(JAsynchDataReceiverT::kDefaultBufferSize)
{
JAsynchDataReceiverX();
}
Expand All @@ -37,7 +37,7 @@ JAsynchDataReceiver<ACE_PEER_STREAM_2>::JAsynchDataReceiver
)
:
ACE_Svc_Handler<ACE_PEER_STREAM_2,ACE_SYNCH>(),
itsByteBuffer(JAsynchDataReceiverT::kDefaultLgBufferSize)
itsByteBuffer(JAsynchDataReceiverT::kDefaultBufferSize)
{
JAsynchDataReceiverX();

Expand All @@ -51,7 +51,7 @@ template <ACE_PEER_STREAM_1>
void
JAsynchDataReceiver<ACE_PEER_STREAM_2>::JAsynchDataReceiverX()
{
itsRecvBufferSize = 1UL << JAsynchDataReceiverT::kDefaultLgBufferSize;
itsRecvBufferSize = JAsynchDataReceiverT::kDefaultBufferSize;
itsRecvBuffer = jnew JUtf8Byte [ itsRecvBufferSize ];
itsCancelTaskFlag = nullptr;
}
Expand Down
9 changes: 1 addition & 8 deletions libjcore/code/JCoreLibVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,8 @@ static const char* kCurrentJCoreLibVersionStr = "4.2.0";
// Fixed bug so original selection is fully cleared after undo/redo.
// JArray:
// Switched to an exponential reallocation model.
// *** Ctor now takes log2(minimum allocation size).
// JStyledText:
// *** SetBlockSizes() now takes lgSize for both arguments.
// JRunArray:
// *** Ctor now takes log2(minimum allocation size).
// JPtrArray:
// *** Ctor now takes log2(minimum allocation size).
// JUtf8ByteBuffer:
// *** Ctor now takes log2(minimum allocation size).
// Renamed SetBlockSizes() to SetLgMinSizes().

// version 4.1.0:
//
Expand Down
6 changes: 4 additions & 2 deletions libjcore/code/JMMArrayTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "JMMRecord.h"
#include "jAssert.h"

const JSize blockSize = 5000;

/******************************************************************************
Constructor
Expand All @@ -34,11 +36,11 @@ JMMArrayTable::JMMArrayTable
itsDeletedCount(0),
itsSnapshotID(0)
{
itsAllocatedTable = jnew JArray<JMMRecord>(12);
itsAllocatedTable = jnew JArray<JMMRecord>(blockSize);

if (recordDelete)
{
itsDeletedTable = jnew JArray<JMMRecord>(12);
itsDeletedTable = jnew JArray<JMMRecord>(blockSize);
}
}

Expand Down
2 changes: 2 additions & 0 deletions libjcore/code/JMessageProtocol.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ JMessageProtocol<ACE_PEER_STREAM_2>::JMessageProtocol
)
:
JNetworkProtocolBase<ACE_PEER_STREAM_2>(synchSend),
itsByteBuffer(JMessageProtocolT::kDefaultBufferSize),
itsMessageList(JPtrArrayT::kDeleteAll),
itsSeparatorStr(JString::kDoNotNormalize),
itsDisconnectStr(JString::kDoNotNormalize)
Expand All @@ -56,6 +57,7 @@ JMessageProtocol<ACE_PEER_STREAM_2>::JMessageProtocol
)
:
JNetworkProtocolBase<ACE_PEER_STREAM_2>(synchSend),
itsByteBuffer(JMessageProtocolT::kDefaultBufferSize),
itsMessageList(JPtrArrayT::kDeleteAll),
itsSeparatorStr(JString::kDoNotNormalize),
itsDisconnectStr(JString::kDoNotNormalize)
Expand Down
4 changes: 2 additions & 2 deletions libjcore/code/JPtrArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class JPtrArray : public JArray<T*>
{
public:

JPtrArray(const JPtrArrayT::CleanUpAction action, const JSize minLgSize = 0);
JPtrArray(const JPtrArrayT::CleanUpAction action, const JSize minSize = 0);
JPtrArray(const JPtrArray<T>& source, const JPtrArrayT::CleanUpAction action);
JPtrArray(JPtrArray<T>&& dyingSource) noexcept;

Expand Down Expand Up @@ -95,7 +95,7 @@ class JDCCPtrArray : public JPtrArray<T>
{
public:

JDCCPtrArray(const JPtrArrayT::CleanUpAction action, const JSize minLgSize = 0);
JDCCPtrArray(const JPtrArrayT::CleanUpAction action, const JSize minSize = 0);
JDCCPtrArray(const JPtrArray<T>& source, const JPtrArrayT::CleanUpAction action);
};

Expand Down
8 changes: 4 additions & 4 deletions libjcore/code/JPtrArray.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ template <class T>
JPtrArray<T>::JPtrArray
(
const JPtrArrayT::CleanUpAction action,
const JSize minLgSize
const JSize minSize
)
:
JArray<T*>(minLgSize),
JArray<T*>(minSize),
itsCleanUpAction(action)
{
}
Expand Down Expand Up @@ -91,10 +91,10 @@ template <class T>
JDCCPtrArray<T>::JDCCPtrArray
(
const JPtrArrayT::CleanUpAction action,
const JSize minLgSize
const JSize minSize
)
:
JPtrArray<T>(action, minLgSize)
JPtrArray<T>(action, minSize)
{
}

Expand Down
2 changes: 1 addition & 1 deletion libjcore/code/JRunArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class JRunArray : public JList<T>

public:

JRunArray(const JSize minLgSize = 0);
JRunArray(const JSize minSize = 0);
JRunArray(const JRunArray<T>& source);
JRunArray(const JRunArray<T>& source, const JIndexRange& range);

Expand Down
7 changes: 4 additions & 3 deletions libjcore/code/JRunArray.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
template <class T>
JRunArray<T>::JRunArray
(
const JSize minLgSize
const JSize minSize
)
:
JList<T>()
{
itsRuns = jnew JArray< JRunArrayItem<T> >(minLgSize);
itsRuns = jnew JArray< JRunArrayItem<T> >(minSize);
}

/******************************************************************************
Expand All @@ -67,7 +67,8 @@ JRunArray<T>::JRunArray
const JIndexRange& range
)
{
itsRuns = jnew JArray< JRunArrayItem<T> >(source.itsRuns->GetMinLgSize());
itsRuns = jnew JArray< JRunArrayItem<T> >;
itsRuns->SetMinLgSize(source.itsRuns->GetMinLgSize());

JIndex runIndex = 1, firstIndexInRun = 1;
IteratorInsertSlice(1, source, range, &runIndex, &firstIndexInRun);
Expand Down
4 changes: 2 additions & 2 deletions libjcore/code/JSTStyler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using TextCount = JStyledText::TextCount;
using TextRange = JStyledText::TextRange;

const JSize kDecimationFactor = 50;
const JSize kMinLgListSize = 7;
const JSize kMinListSize = 50;

#define DEBUG_TIMING_INFO 0 // boolean

Expand Down Expand Up @@ -416,7 +416,7 @@ JSTStyler::SetStyle
JArray<JSTStyler::TokenData>*
JSTStyler::NewTokenStartList()
{
auto* list = jnew JArray<TokenData>(kMinLgListSize);
auto* list = jnew JArray<TokenData>(kMinListSize);
list->SetSortOrder(JListT::kSortAscending);
list->SetCompareFunction(CompareTokenStarts);
return list;
Expand Down
Loading

0 comments on commit c06cee5

Please sign in to comment.