mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:42:43 +00:00 
			
		
		
		
	 3ec513ecf2
			
		
	
	
		3ec513ecf2
		
	
	
	
	
		
			
			This improves the decompression time of `clang-15.0.7.src.tar.xz` from 41 seconds down to about 5 seconds. The reason for this very significant improvement is that LZMA, the underlying compression of XZ, fills its range decompressor one byte at a time, causing a lot of overhead at the syscall barrier.
		
			
				
	
	
		
			36 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2023, Tim Schumacher <timschumi@gmx.de>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibCompress/Xz.h>
 | |
| #include <LibCore/ArgsParser.h>
 | |
| #include <LibCore/File.h>
 | |
| #include <LibCore/System.h>
 | |
| #include <LibMain/Main.h>
 | |
| 
 | |
| ErrorOr<int> serenity_main(Main::Arguments arguments)
 | |
| {
 | |
|     TRY(Core::System::pledge("rpath stdio"));
 | |
| 
 | |
|     StringView filename;
 | |
| 
 | |
|     Core::ArgsParser args_parser;
 | |
|     args_parser.set_general_help("Decompress and print an XZ archive");
 | |
|     args_parser.add_positional_argument(filename, "File to decompress", "file");
 | |
|     args_parser.parse(arguments);
 | |
| 
 | |
|     auto file = TRY(Core::File::open_file_or_standard_stream(filename, Core::File::OpenMode::Read));
 | |
|     auto buffered_file = TRY(Core::BufferedFile::create(move(file)));
 | |
|     auto stream = TRY(Compress::XzDecompressor::create(move(buffered_file)));
 | |
| 
 | |
|     // Arbitrarily chosen buffer size.
 | |
|     Array<u8, 4096> buffer;
 | |
|     while (!stream->is_eof()) {
 | |
|         auto slice = TRY(stream->read_some(buffer));
 | |
|         out("{:s}", slice);
 | |
|     }
 | |
| 
 | |
|     return 0;
 | |
| }
 |