diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C index 727e8803ac..5a001a1932 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C @@ -42,13 +42,13 @@ Foam::Istream& Foam::operator>>(Istream& is, CompactListList& lst) { is >> lst.offsets_ >> lst.m_; // Note: empty list gets output as two empty lists - if (lst.offsets_.size() == 0) + if (lst.offsets_.size()) { - lst.size_ = 0; + lst.size_ = lst.offsets_.size()-1; } else { - lst.size_ = lst.offsets_.size()-1; + lst.size_ = 0; } return is; } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 9119234ef6..31cf08ada6 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -118,6 +118,8 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& L) } else { + // contents are binary and contiguous + is.read(reinterpret_cast(L.data()), Size*sizeof(T)); is.fatalCheck @@ -167,12 +169,10 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) // Write list contents depending on data format if (os.format() == IOstream::ASCII || !contiguous()) { - bool uniform = false; - - if (Size > 1 && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (Size > 1 && contiguous()); + if (uniform) { - uniform = true; - forAll(L, i) { if (L[i] != L[0]) @@ -194,7 +194,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) // Write end delimiter os << token::END_BLOCK; } - else if (Size <= 1 ||(Size < 11 && contiguous())) + else if (Size <= 1 || (Size < 11 && contiguous())) { // Write start delimiter os << token::BEGIN_LIST; @@ -202,7 +202,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) // Write contents forAll(L, i) { - if (i > 0) os << token::SPACE; + if (i) os << token::SPACE; os << L[i]; } @@ -226,6 +226,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& L) } else { + // Contents are binary and contiguous + + // write(...) includes surrounding start/end delimiters os.write(reinterpret_cast(L.cdata()), Size*sizeof(T)); } diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index d43fda22d7..bbc55ec10d 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -92,6 +92,8 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) } else { + // uniform content (delimiter == token::BEGIN_BLOCK) + T element; is >> element; @@ -113,6 +115,8 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) } else { + // contents are binary and contiguous + if (s) { is.read(reinterpret_cast(L.data()), s*sizeof(T)); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C index 5e0487ebcd..6addd5d23e 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C @@ -407,12 +407,10 @@ Foam::Ostream& Foam::PackedList::write // Write list contents depending on data format if (os.format() == IOstream::ASCII) { - bool uniform = false; - - if (sz > 1 && !indexedOutput) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (sz > 1 && !indexedOutput); + if (uniform) { - uniform = true; - forAll(lst, i) { if (lst[i] != lst[0]) @@ -475,9 +473,12 @@ Foam::Ostream& Foam::PackedList::write } else { + // Contents are binary and contiguous + os << nl << sz << nl; if (sz) { + // write(...) includes surrounding start/end delimiters os.write ( reinterpret_cast(lst.storage().cdata()), diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C index 18f1f5fe94..3b52f8484c 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,12 +40,10 @@ Foam::Ostream& Foam::operator<< // Write list contents depending on data format if (os.format() == IOstream::ASCII || !contiguous()) { - bool uniform = false; - - if (L.size() > 1 && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (L.size() > 1 && contiguous()); + if (uniform) { - uniform = true; - forAll(L, i) { if (L[i] != L[0]) @@ -99,14 +97,15 @@ Foam::Ostream& Foam::operator<< } else { - // this is annoying, and wasteful, but there's currently no alternative - + // Contents are binary and contiguous os << nl << L.size() << nl; if (L.size()) { + // This is annoying, and wasteful, but currently no alternative List lst = L(); + // write(...) includes surrounding start/end delimiters os.write ( reinterpret_cast(lst.cdata()), diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index e31b5dd2bc..cba400379f 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,12 +65,10 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList& L) // Write list contents depending on data format if (os.format() == IOstream::ASCII || !contiguous()) { - bool uniform = false; - - if (L.size() > 1 && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (L.size() > 1 && contiguous()); + if (uniform) { - uniform = true; - forAll(L, i) { if (L[i] != L[0]) @@ -100,7 +98,7 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList& L) // Write contents forAll(L, i) { - if (i > 0) os << token::SPACE; + if (i) os << token::SPACE; os << L[i]; } @@ -124,10 +122,13 @@ Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList& L) } else { + // Contents are binary and contiguous os << nl << L.size() << nl; + if (L.size()) { - os.write(reinterpret_cast(L.v_), L.byteSize()); + // write(...) includes surrounding start/end delimiters + os.write(reinterpret_cast(L.cdata()), L.byteSize()); } } @@ -208,6 +209,8 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) } else { + // uniform content (delimiter == token::BEGIN_BLOCK) + T element; is >> element; @@ -229,6 +232,8 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) } else { + // contents are binary and contiguous + if (s) { is.read(reinterpret_cast(L.data()), s*sizeof(T)); diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index 1c021bcca2..997135bc34 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -727,12 +727,10 @@ void Foam::Field::writeEntry(const word& keyword, Ostream& os) const { os.writeKeyword(keyword); - bool uniform = false; - - if (this->size() && contiguous()) + // Can the contents be considered 'uniform' (ie, identical)? + bool uniform = (this->size() && contiguous()); + if (uniform) { - uniform = true; - forAll(*this, i) { if (this->operator[](i) != this->operator[](0)) diff --git a/src/OpenFOAM/matrices/Matrix/MatrixIO.C b/src/OpenFOAM/matrices/Matrix/MatrixIO.C index 154a066914..b965bb37d7 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixIO.C +++ b/src/OpenFOAM/matrices/Matrix/MatrixIO.C @@ -160,15 +160,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) { if (mn) { - bool uniform = false; - const Type* v = M.v_; - if (mn > 1 && contiguous()) + // can the contents be considered 'uniform' (ie, identical) + bool uniform = (mn > 1 && contiguous()); + if (uniform) { - uniform = true; - - for (label i=0; i& M) if (uniform) { - // Write size of list and start contents delimiter + // Write start delimiter os << token::BEGIN_BLOCK; - // Write list contents + // Write contents os << v[0]; - // Write end of contents delimiter + // Write end delimiter os << token::END_BLOCK; } else if (mn < 10 && contiguous()) { - // Write size of list and start contents delimiter + // Write start contents delimiter os << token::BEGIN_LIST; label k = 0; @@ -204,7 +202,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) // Write row for (label j=0; j< M.n(); j++) { - if (j > 0) os << token::SPACE; + if (j) os << token::SPACE; os << v[k++]; } @@ -216,7 +214,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) } else { - // Write size of list and start contents delimiter + // Write start contents delimiter os << nl << token::BEGIN_LIST; label k = 0;