Commit d50b5edb authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Refactoring: Flatten the call graph.

parent 9a5d4d90
......@@ -1228,7 +1228,7 @@ ZgyInternalBulk::_writeWithRetry(const WriteNowArgPack& args)
*
* Args: brickpos, lod, data, compressor, fileoffset.
*/
void
std::shared_ptr<const WriteNowArgPack>
ZgyInternalBulk::_writeOneNormalBrick(const WriteBrickArgPack& args)
{
const double defaultstorage = this->_metadata->ih().defaultstorage();
......@@ -1285,8 +1285,9 @@ ZgyInternalBulk::_writeOneNormalBrick(const WriteBrickArgPack& args)
// It might be safer to unconditionally copy the data.
//data->byteswap();
}
_writeWithRetry(WriteNowArgPack(args.brickpos, args.lod, args.fileoffset,
rawdata, brickstatus));
// Arguments that our caller needs to be pass to _writeWithRetry()
return std::make_shared<const WriteNowArgPack>
(args.brickpos, args.lod, args.fileoffset, rawdata, brickstatus);
}
/**
......@@ -1412,7 +1413,7 @@ ZgyInternalBulk::_mustLeakOldBrick(
*
* Args: brickpos, lod, data, compressor, fileoffset.
*/
void
std::shared_ptr<const WriteBrickArgPack>
ZgyInternalBulk::_writeOneBrick(const WriteBrickArgPack& args_in)
{
WriteBrickArgPack args(args_in);
......@@ -1444,7 +1445,6 @@ ZgyInternalBulk::_writeOneBrick(const WriteBrickArgPack& args_in)
if (data_const) {
// Caller asked to store a constant value.
_logger(1, "Explicit store constant.\n");
_writeOneConstantBrick(args);
}
else if (_isUsedPartOfBrickAllConstant(args.data, args.brickpos, args.lod)) {
// Caller did not explicitly ask for a constant value,
......@@ -1462,12 +1462,10 @@ ZgyInternalBulk::_writeOneBrick(const WriteBrickArgPack& args_in)
// Or the other way, create an inflated brick from a constant.
double value = args.data->scalarAsDouble();
args.data = DataBuffer::makeDataBuffer3d(&value, sizeof(double), bs, args.data->datatype());
_writeOneConstantBrick(args);
}
else {
_logger(1, "Store a new brick.\n");
args.fileoffset = 0; // Says to allocate a new block on file.
_writeOneNormalBrick(args);
}
}
else { // !file_const
......@@ -1501,15 +1499,18 @@ ZgyInternalBulk::_writeOneBrick(const WriteBrickArgPack& args_in)
args.data->fill(value);
args.fileoffset = info.offset_in_file; // Re-use if possible.
args.compressor = compressor_t(); // No compress on update.
_writeOneNormalBrick(args);
}
else {
_logger(1, "Update a brick.\n");
args.fileoffset = info.offset_in_file; // Re-use if possible.
args.compressor = compressor_t(); // No compress on update.
_writeOneNormalBrick(args);
}
}
// Next, _writeOneNormalBrick or _writeOneConstantBrick
// (depending on the type that args.data has now)
// should be called with the modified argument pack.
// TODO-Low: Don't copy args so often.
return std::make_shared<const WriteBrickArgPack>(args);
}
/**
......@@ -1621,7 +1622,18 @@ ZgyInternalBulk::_writeAlignedRegion(
// recover from.
ErrorsWillCorruptFile watchdog(this);
_writeOneBrick(WriteBrickArgPack(brickpos, lod, brick, compressor, 0));
std::shared_ptr<const WriteBrickArgPack> args =
std::make_shared<const WriteBrickArgPack>
(brickpos, lod, brick, compressor, 0);
args = _writeOneBrick(*args);
if (args->data->isScalar()) {
_writeOneConstantBrick(*args);
}
else {
std::shared_ptr<const WriteNowArgPack> now =
_writeOneNormalBrick(*args);
_writeWithRetry(*now);
}
watchdog.disarm();
}
}
......@@ -1747,5 +1759,5 @@ ZgyInternalBulk::writeRegion(
// Refactoring 12-Jan-2021
// (delete this comment after things check out)
//
// * _writeOneBrick, _writeIneNormalBrick, _writeOneConstamtBrick
// * _writeOneBrick, _writeIneNormalBrick, _writeOneConstantBrick
// now use an argument package as input.
......@@ -181,7 +181,8 @@ private:
void _writeWithRetry(const WriteNowArgPack& args);
void _writeOneNormalBrick(const WriteBrickArgPack& args);
std::shared_ptr<const WriteNowArgPack>
_writeOneNormalBrick(const WriteBrickArgPack& args);
void _writeOneConstantBrick(const WriteBrickArgPack& args);
......@@ -190,7 +191,8 @@ private:
const compressor_t& compressor,
BrickStatus brickstatus) const;
void _writeOneBrick(const WriteBrickArgPack& args);
std::shared_ptr<const WriteBrickArgPack>
_writeOneBrick(const WriteBrickArgPack& args);
void _writeAlignedRegion(
const std::shared_ptr<DataBuffer>& data,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment