Skip to content

Commit

Permalink
Put the copy code in one function. Runs just as fast or faster.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed May 28, 2020
1 parent 0a995b0 commit 4eaff5b
Showing 1 changed file with 19 additions and 55 deletions.
74 changes: 19 additions & 55 deletions pdal/ColumnPointTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,12 @@ PointId ColumnPointTable::addPoint()
return m_numPts++;
}


void ColumnPointTable::setFieldInternal(Dimension::Id dim,
PointId idx, const void *src)
namespace
{
const Dimension::Detail *d = m_layoutRef.dimDetail(dim);
const DimBlockList& dimBlocks = m_blocks[d->order()];
char *buf = dimBlocks[idx / m_blockPtCnt];
char *dst = buf + (Dimension::size(d->type()) * (idx % m_blockPtCnt));

switch (d->type())
void copy(const char *src, char *dst, Dimension::Type type)
{
switch (type)
{
case Dimension::Type::Double:
*reinterpret_cast<double *>(dst) =
Expand Down Expand Up @@ -128,6 +124,20 @@ void ColumnPointTable::setFieldInternal(Dimension::Id dim,
}
}

} // unnamed namespace


void ColumnPointTable::setFieldInternal(Dimension::Id dim,
PointId idx, const void *src)
{
const Dimension::Detail *d = m_layoutRef.dimDetail(dim);
const DimBlockList& dimBlocks = m_blocks[d->order()];
char *buf = dimBlocks[idx / m_blockPtCnt];
char *dst = buf + (Dimension::size(d->type()) * (idx % m_blockPtCnt));

copy (reinterpret_cast<const char *>(src), dst, d->type());
}


void ColumnPointTable::getFieldInternal(Dimension::Id dim,
PointId idx, void *dst) const
Expand All @@ -137,55 +147,9 @@ void ColumnPointTable::getFieldInternal(Dimension::Id dim,
const char *buf = dimBlocks[idx / m_blockPtCnt];
const char *src = buf + (Dimension::size(d->type()) * (idx % m_blockPtCnt));

switch (d->type())
{
case Dimension::Type::Double:
*reinterpret_cast<double *>(dst) =
*reinterpret_cast<const double *>(src);
break;
case Dimension::Type::Float:
*reinterpret_cast<float *>(dst) =
*reinterpret_cast<const float*>(src);
break;
case Dimension::Type::Signed8:
*reinterpret_cast<int8_t *>(dst) =
*reinterpret_cast<const int8_t *>(src);
break;
case Dimension::Type::Signed16:
*reinterpret_cast<int16_t *>(dst) =
*reinterpret_cast<const int16_t *>(src);
break;
case Dimension::Type::Signed32:
*reinterpret_cast<int32_t *>(dst) =
*reinterpret_cast<const int32_t *>(src);
break;
case Dimension::Type::Signed64:
*reinterpret_cast<int64_t *>(dst) =
*reinterpret_cast<const int64_t *>(src);
break;
case Dimension::Type::Unsigned8:
*reinterpret_cast<uint8_t *>(dst) =
*reinterpret_cast<const uint8_t *>(src);
break;
case Dimension::Type::Unsigned16:
*reinterpret_cast<uint16_t *>(dst) =
*reinterpret_cast<const uint16_t *>(src);
break;
case Dimension::Type::Unsigned32:
*reinterpret_cast<uint32_t *>(dst) =
*reinterpret_cast<const uint32_t *>(src);
break;
case Dimension::Type::Unsigned64:
*reinterpret_cast<uint64_t *>(dst) =
*reinterpret_cast<const uint64_t *>(src);
break;
case Dimension::Type::None:
default:
break;
}
copy(src, reinterpret_cast<char *>(dst), d->type());
}


char *ColumnPointTable::getDimension(const Dimension::Detail *d, PointId idx)
{
DimBlockList& dimBlocks = m_blocks[d->order()];
Expand Down

0 comments on commit 4eaff5b

Please sign in to comment.