From c123ca1054bd4dd31089aa052b40b64ca4f5a3dd Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 16 Jul 2019 18:05:58 -0400 Subject: [PATCH] Slightly improves syntax. --- Storage/Disk/Track/PCMTrack.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Storage/Disk/Track/PCMTrack.cpp b/Storage/Disk/Track/PCMTrack.cpp index 13ab2dfd2..85da85c47 100644 --- a/Storage/Disk/Track/PCMTrack.cpp +++ b/Storage/Disk/Track/PCMTrack.cpp @@ -165,7 +165,7 @@ void PCMTrack::add_segment(const Time &start_time, const PCMSegment &segment, bo const size_t selected_end_bit = std::min(end_bit, destination.data.size()); // Reset the destination. - std::fill(destination.data.begin() + static_cast(start_bit), destination.data.begin() + static_cast(selected_end_bit), false); + std::fill(destination.data.begin() + off_t(start_bit), destination.data.begin() + off_t(selected_end_bit), false); // Step through the source data from start to finish, stopping early if it goes out of bounds. for(size_t bit = 0; bit < segment.data.size(); ++bit) { @@ -184,15 +184,19 @@ void PCMTrack::add_segment(const Time &start_time, const PCMSegment &segment, bo if(target_width >= destination.data.size()) { std::fill(destination.data.begin(), destination.data.end(), false); } else { - std::fill(destination.data.begin(), destination.data.begin() + static_cast(end_bit % destination.data.size()), false); - std::fill(destination.data.begin() + static_cast(start_bit), destination.data.end(), false); + std::fill(destination.data.begin(), destination.data.begin() + off_t(end_bit % destination.data.size()), false); + std::fill(destination.data.begin() + off_t(start_bit), destination.data.end(), false); } // Run backwards from final bit back to first, stopping early if overlapping the beginning. - for(off_t bit = static_cast(segment.data.size()-1); bit >= 0; --bit) { - if(segment.data[static_cast(bit)]) { - const size_t output_bit = start_bit + half_offset + (static_cast(bit) * target_width) / segment.data.size(); - if(output_bit <= end_bit - destination.data.size()) return; + for(off_t bit = off_t(segment.data.size()-1); bit >= 0; --bit) { + // Store flux transitions only; non-transitions can be ignored. + if(segment.data[size_t(bit)]) { + // Map to the proper output destination; stop if now potentially overwriting where we began. + const size_t output_bit = start_bit + half_offset + (size_t(bit) * target_width) / segment.data.size(); + if(output_bit < end_bit - destination.data.size()) return; + + // Store. destination.data[output_bit % destination.data.size()] = true; } }