diff options
author | asynts <asynts@gmail.com> | 2020-09-06 21:40:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-08 14:01:21 +0200 |
commit | 9c83d6ff468870c58f2a81673b29d96106f543fb (patch) | |
tree | 0a66b1d4477cae34d806360daa739cd3a4bd7e45 | |
parent | 76e37e8c968e62abf597afdd4554714c6d40ef92 (diff) | |
download | serenity-9c83d6ff468870c58f2a81673b29d96106f543fb.zip |
Refactor: Replace usages of FixedArray with Array.
-rw-r--r-- | AK/Tests/TestMemoryStream.cpp | 4 | ||||
-rw-r--r-- | Applications/Piano/Track.h | 1 | ||||
-rw-r--r-- | Applications/Piano/TrackManager.cpp | 10 | ||||
-rw-r--r-- | Applications/Piano/TrackManager.h | 13 | ||||
-rw-r--r-- | Applications/Piano/main.cpp | 3 | ||||
-rw-r--r-- | Kernel/Interrupts/InterruptManagement.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibCompress/Deflate.cpp | 16 | ||||
-rw-r--r-- | Userland/test-compress.cpp | 56 |
8 files changed, 52 insertions, 54 deletions
diff --git a/AK/Tests/TestMemoryStream.cpp b/AK/Tests/TestMemoryStream.cpp index 61e8266af4..9f17e0a27e 100644 --- a/AK/Tests/TestMemoryStream.cpp +++ b/AK/Tests/TestMemoryStream.cpp @@ -26,7 +26,7 @@ #include <AK/TestSuite.h> -#include <AK/FixedArray.h> +#include <AK/Array.h> #include <AK/MemoryStream.h> static bool compare(ReadonlyBytes lhs, ReadonlyBytes rhs) @@ -127,7 +127,7 @@ TEST_CASE(duplex_large_buffer) { DuplexMemoryStream stream; - FixedArray<u8> one_kibibyte { 1024 }; + Array<u8, 1024> one_kibibyte; EXPECT_EQ(stream.remaining(), 0ul); diff --git a/Applications/Piano/Track.h b/Applications/Piano/Track.h index 276e7e8bdb..0acca429b0 100644 --- a/Applications/Piano/Track.h +++ b/Applications/Piano/Track.h @@ -28,7 +28,6 @@ #pragma once #include "Music.h" -#include <AK/FixedArray.h> #include <AK/Noncopyable.h> #include <AK/SinglyLinkedList.h> #include <LibAudio/Buffer.h> diff --git a/Applications/Piano/TrackManager.cpp b/Applications/Piano/TrackManager.cpp index 18ae568d09..5aa1856a11 100644 --- a/Applications/Piano/TrackManager.cpp +++ b/Applications/Piano/TrackManager.cpp @@ -36,7 +36,7 @@ TrackManager::~TrackManager() { } -void TrackManager::fill_buffer(FixedArray<Sample>& buffer) +void TrackManager::fill_buffer(Span<Sample> buffer) { memset(buffer.data(), 0, buffer_size); @@ -51,8 +51,8 @@ void TrackManager::fill_buffer(FixedArray<Sample>& buffer) } } - memcpy(m_back_buffer_ptr->data(), buffer.data(), buffer_size); - swap(m_front_buffer_ptr, m_back_buffer_ptr); + memcpy(m_current_back_buffer.data(), buffer.data(), buffer_size); + swap(m_current_front_buffer, m_current_back_buffer); } void TrackManager::reset() @@ -60,8 +60,8 @@ void TrackManager::reset() memset(m_front_buffer.data(), 0, buffer_size); memset(m_back_buffer.data(), 0, buffer_size); - m_front_buffer_ptr = &m_front_buffer; - m_back_buffer_ptr = &m_back_buffer; + m_current_front_buffer = m_front_buffer.span(); + m_current_back_buffer = m_back_buffer.span(); m_time = 0; diff --git a/Applications/Piano/TrackManager.h b/Applications/Piano/TrackManager.h index 79331a5586..70cb661bc4 100644 --- a/Applications/Piano/TrackManager.h +++ b/Applications/Piano/TrackManager.h @@ -29,6 +29,7 @@ #include "Music.h" #include "Track.h" +#include <AK/Array.h> #include <AK/Noncopyable.h> #include <AK/NonnullOwnPtr.h> #include <AK/Vector.h> @@ -42,12 +43,12 @@ public: ~TrackManager(); Track& current_track() { return *m_tracks[m_current_track]; } - const FixedArray<Sample>& buffer() const { return *m_front_buffer_ptr; } + Span<const Sample> buffer() const { return m_current_front_buffer; } int octave() const { return m_octave; } int octave_base() const { return (m_octave - octave_min) * 12; } int time() const { return m_time; } - void fill_buffer(FixedArray<Sample>& buffer); + void fill_buffer(Span<Sample>); void reset(); void set_should_loop(bool b) { m_should_loop = b; } void set_note_current_octave(int note, Switch); @@ -60,10 +61,10 @@ private: Vector<NonnullOwnPtr<Track>> m_tracks; size_t m_current_track { 0 }; - FixedArray<Sample> m_front_buffer { sample_count }; - FixedArray<Sample> m_back_buffer { sample_count }; - FixedArray<Sample>* m_front_buffer_ptr { &m_front_buffer }; - FixedArray<Sample>* m_back_buffer_ptr { &m_back_buffer }; + Array<Sample, sample_count> m_front_buffer; + Array<Sample, sample_count> m_back_buffer; + Span<Sample> m_current_front_buffer { m_front_buffer.span() }; + Span<Sample> m_current_back_buffer { m_back_buffer.span() }; int m_octave { 4 }; diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index cfcee1a709..5666f7aa20 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -27,6 +27,7 @@ #include "MainWidget.h" #include "TrackManager.h" +#include <AK/Array.h> #include <LibAudio/ClientConnection.h> #include <LibAudio/WavWriter.h> #include <LibCore/EventLoop.h> @@ -69,7 +70,7 @@ int main(int argc, char** argv) return 1; } - FixedArray<Sample> buffer(sample_count); + Array<Sample, sample_count> buffer; for (;;) { track_manager.fill_buffer(buffer); audio->write(reinterpret_cast<u8*>(buffer.data()), buffer_size); diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp index e368c811d9..e92d78bc5e 100644 --- a/Kernel/Interrupts/InterruptManagement.cpp +++ b/Kernel/Interrupts/InterruptManagement.cpp @@ -24,9 +24,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <AK/FixedArray.h> #include <AK/StringView.h> #include <Kernel/ACPI/MultiProcessorParser.h> +#include <Kernel/API/Syscall.h> #include <Kernel/Arch/i386/CPU.h> #include <Kernel/CommandLine.h> #include <Kernel/IO.h> @@ -36,7 +36,6 @@ #include <Kernel/Interrupts/PIC.h> #include <Kernel/Interrupts/SpuriousInterruptHandler.h> #include <Kernel/Interrupts/UnhandledInterruptHandler.h> -#include <Kernel/API/Syscall.h> #include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/TypedMapping.h> diff --git a/Libraries/LibCompress/Deflate.cpp b/Libraries/LibCompress/Deflate.cpp index 25f69c737e..f2fab5e3d8 100644 --- a/Libraries/LibCompress/Deflate.cpp +++ b/Libraries/LibCompress/Deflate.cpp @@ -24,9 +24,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/Array.h> #include <AK/Assertions.h> #include <AK/BinarySearch.h> -#include <AK/FixedArray.h> #include <AK/LogStream.h> #include <AK/MemoryStream.h> @@ -42,11 +42,11 @@ const DeflateDecompressor::CanonicalCode& DeflateDecompressor::CanonicalCode::fi if (initialized) return code; - FixedArray<u8> data { 288 }; - data.bytes().slice(0, 144 - 0).fill(8); - data.bytes().slice(144, 256 - 144).fill(9); - data.bytes().slice(256, 280 - 256).fill(7); - data.bytes().slice(280, 288 - 280).fill(8); + Array<u8, 288> data; + data.span().slice(0, 144 - 0).fill(8); + data.span().slice(144, 256 - 144).fill(9); + data.span().slice(256, 280 - 256).fill(7); + data.span().slice(280, 288 - 280).fill(8); code = CanonicalCode::from_bytes(data).value(); initialized = true; @@ -62,8 +62,8 @@ const DeflateDecompressor::CanonicalCode& DeflateDecompressor::CanonicalCode::fi if (initialized) return code; - FixedArray<u8> data { 32 }; - data.bytes().fill(5); + Array<u8, 32> data; + data.span().fill(5); code = CanonicalCode::from_bytes(data).value(); initialized = true; diff --git a/Userland/test-compress.cpp b/Userland/test-compress.cpp index 04c4b10cde..f2670483af 100644 --- a/Userland/test-compress.cpp +++ b/Userland/test-compress.cpp @@ -26,7 +26,7 @@ #include <AK/TestSuite.h> -#include <AK/FixedArray.h> +#include <AK/Array.h> #include <LibCompress/Deflate.h> #include <LibCompress/Gzip.h> #include <LibCompress/Zlib.h> @@ -46,7 +46,7 @@ static bool compare(ReadonlyBytes lhs, ReadonlyBytes rhs) TEST_CASE(deflate_decompress_compressed_block) { - const u8 compressed[] = { + const Array<u8, 28> compressed { 0x0B, 0xC9, 0xC8, 0x2C, 0x56, 0x00, 0xA2, 0x44, 0x85, 0xE2, 0xCC, 0xDC, 0x82, 0x9C, 0x54, 0x85, 0x92, 0xD4, 0x8A, 0x12, 0x85, 0xB4, 0x4C, 0x20, 0xCB, 0x4A, 0x13, 0x00 @@ -54,26 +54,26 @@ TEST_CASE(deflate_decompress_compressed_block) const u8 uncompressed[] = "This is a simple text file :)"; - const auto decompressed = Compress::DeflateDecompressor::decompress_all({ compressed, sizeof(compressed) }); + const auto decompressed = Compress::DeflateDecompressor::decompress_all(compressed); EXPECT(compare({ uncompressed, sizeof(uncompressed) - 1 }, decompressed.bytes())); } TEST_CASE(deflate_decompress_uncompressed_block) { - const u8 compressed[] = { + const Array<u8, 18> compressed { 0x01, 0x0d, 0x00, 0xf2, 0xff, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 }; const u8 uncompressed[] = "Hello, World!"; - const auto decompressed = Compress::DeflateDecompressor::decompress_all({ compressed, sizeof(compressed) }); + const auto decompressed = Compress::DeflateDecompressor::decompress_all(compressed); EXPECT(compare({ uncompressed, sizeof(uncompressed) - 1 }, decompressed.bytes())); } TEST_CASE(deflate_decompress_multiple_blocks) { - const u8 compressed[] = { + const Array<u8, 84> compressed { 0x00, 0x1f, 0x00, 0xe0, 0xff, 0x54, 0x68, 0x65, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x69, 0x73, 0x20, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, @@ -84,27 +84,26 @@ TEST_CASE(deflate_decompress_multiple_blocks) const u8 uncompressed[] = "The first block is uncompressed and the second block is compressed."; - const auto decompressed = Compress::DeflateDecompressor::decompress_all({ compressed, sizeof(compressed) }); + const auto decompressed = Compress::DeflateDecompressor::decompress_all(compressed); EXPECT(compare({ uncompressed, sizeof(uncompressed) - 1 }, decompressed.bytes())); } TEST_CASE(deflate_decompress_zeroes) { - const u8 compressed[] = { + const Array<u8, 20> compressed { 0xed, 0xc1, 0x01, 0x0d, 0x00, 0x00, 0x00, 0xc2, 0xa0, 0xf7, 0x4f, 0x6d, 0x0f, 0x07, 0x14, 0x00, 0x00, 0x00, 0xf0, 0x6e }; - u8 uncompressed[4096]; - Bytes { uncompressed, sizeof(uncompressed) }.fill(0); + const Array<u8, 4096> uncompressed { 0 }; - const auto decompressed = Compress::DeflateDecompressor::decompress_all({ compressed, sizeof(compressed) }); - EXPECT(compare({ uncompressed, sizeof(uncompressed) }, decompressed.bytes())); + const auto decompressed = Compress::DeflateDecompressor::decompress_all(compressed); + EXPECT(compare(uncompressed, decompressed.bytes())); } TEST_CASE(zlib_decompress_simple) { - const u8 compressed[] = { + const Array<u8, 40> compressed { 0x78, 0x01, 0x01, 0x1D, 0x00, 0xE2, 0xFF, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x73, 0x69, 0x6D, 0x70, 0x6C, 0x65, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x69, 0x6C, 0x65, 0x20, 0x3A, 0x29, @@ -113,13 +112,13 @@ TEST_CASE(zlib_decompress_simple) const u8 uncompressed[] = "This is a simple text file :)"; - const auto decompressed = Compress::Zlib::decompress_all({ compressed, sizeof(compressed) }); + const auto decompressed = Compress::Zlib::decompress_all(compressed); EXPECT(compare({ uncompressed, sizeof(uncompressed) - 1 }, decompressed.bytes())); } TEST_CASE(gzip_decompress_simple) { - const u8 compressed[] = { + const Array<u8, 33> compressed { 0x1f, 0x8b, 0x08, 0x00, 0x77, 0xff, 0x47, 0x5f, 0x02, 0xff, 0x2b, 0xcf, 0x2f, 0x4a, 0x31, 0x54, 0x48, 0x4c, 0x4a, 0x56, 0x28, 0x07, 0xb2, 0x8c, 0x00, 0xc2, 0x1d, 0x22, 0x15, 0x0f, 0x00, 0x00, 0x00 @@ -127,14 +126,13 @@ TEST_CASE(gzip_decompress_simple) const u8 uncompressed[] = "word1 abc word2"; - const auto decompressed = Compress::GzipDecompressor::decompress_all({ compressed, sizeof(compressed) }); + const auto decompressed = Compress::GzipDecompressor::decompress_all(compressed); EXPECT(compare({ uncompressed, sizeof(uncompressed) - 1 }, decompressed.bytes())); } TEST_CASE(gzip_decompress_multiple_members) { - - const u8 compressed[] = { + const Array<u8, 52> compressed { 0x1f, 0x8b, 0x08, 0x00, 0xe0, 0x03, 0x48, 0x5f, 0x02, 0xff, 0x4b, 0x4c, 0x4a, 0x4e, 0x4c, 0x4a, 0x06, 0x00, 0x4c, 0x99, 0x6e, 0x72, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x8b, 0x08, 0x00, 0xe0, 0x03, 0x48, 0x5f, 0x02, 0xff, @@ -144,13 +142,13 @@ TEST_CASE(gzip_decompress_multiple_members) const u8 uncompressed[] = "abcabcabcabc"; - const auto decompressed = Compress::GzipDecompressor::decompress_all({ compressed, sizeof(compressed) }); + const auto decompressed = Compress::GzipDecompressor::decompress_all(compressed); EXPECT(compare({ uncompressed, sizeof(uncompressed) - 1 }, decompressed.bytes())); } TEST_CASE(gzip_decompress_zeroes) { - const u8 compressed[] = { + const Array<u8, 161> compressed { 0x1f, 0x8b, 0x08, 0x00, 0x6e, 0x7a, 0x4b, 0x5f, 0x02, 0xff, 0xed, 0xc1, 0x31, 0x01, 0x00, 0x00, 0x00, 0xc2, 0xa0, 0xf5, 0x4f, 0xed, 0x61, 0x0d, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -167,15 +165,15 @@ TEST_CASE(gzip_decompress_zeroes) 0x7e, 0x00, 0x00, 0x02, 0x00 }; - const u8 uncompressed[128 * 1024] = { 0 }; + const Array<u8, 128 * 1024> uncompressed = { 0 }; - const auto decompressed = Compress::GzipDecompressor::decompress_all({ compressed, sizeof(compressed) }); - EXPECT(compare({ uncompressed, sizeof(uncompressed) }, decompressed.bytes())); + const auto decompressed = Compress::GzipDecompressor::decompress_all(compressed); + EXPECT(compare(uncompressed, decompressed.bytes())); } TEST_CASE(gzip_decompress_repeat_around_buffer) { - const u8 compressed[] = { + const Array<u8, 70> compressed { 0x1f, 0x8b, 0x08, 0x00, 0xc6, 0x74, 0x53, 0x5f, 0x02, 0xff, 0xed, 0xc1, 0x01, 0x0d, 0x00, 0x00, 0x0c, 0x02, 0xa0, 0xdb, 0xbf, 0xf4, 0x37, 0x6b, 0x08, 0x24, 0xdb, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -184,12 +182,12 @@ TEST_CASE(gzip_decompress_repeat_around_buffer) 0xb8, 0x07, 0xcd, 0xe5, 0x38, 0xfa, 0x00, 0x80, 0x00, 0x00 }; - FixedArray<u8> uncompressed { 0x8000 }; - uncompressed.bytes().slice(0x0, 0x100).fill(1); - uncompressed.bytes().slice(0x100, 0x7e00).fill(0); - uncompressed.bytes().slice(0x7f00, 0x100).fill(1); + Array<u8, 0x8000> uncompressed; + uncompressed.span().slice(0x0000, 0x0100).fill(1); + uncompressed.span().slice(0x0100, 0x7e00).fill(0); + uncompressed.span().slice(0x7f00, 0x0100).fill(1); - const auto decompressed = Compress::GzipDecompressor::decompress_all({ compressed, sizeof(compressed) }); + const auto decompressed = Compress::GzipDecompressor::decompress_all(compressed); EXPECT(compare(uncompressed, decompressed.bytes())); } |