mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:32:45 +00:00 
			
		
		
		
	LibCompress: Make DeflateCompressor::write() use loop, not recursion
This is performance-neutral, but Instruments.app had a hard time visualizing the very deeply nested stack frames here. No behavior change.
This commit is contained in:
		
							parent
							
								
									e26aebca4f
								
							
						
					
					
						commit
						dfb45705e6
					
				
					 1 changed files with 10 additions and 8 deletions
				
			
		|  | @ -477,16 +477,18 @@ ErrorOr<size_t> DeflateCompressor::write(ReadonlyBytes bytes) | |||
| { | ||||
|     VERIFY(!m_finished); | ||||
| 
 | ||||
|     if (bytes.size() == 0) | ||||
|         return 0; // recursion base case
 | ||||
|     size_t total_written = 0; | ||||
|     while (!bytes.is_empty()) { | ||||
|         auto n_written = bytes.copy_trimmed_to(pending_block().slice(m_pending_block_size)); | ||||
|         m_pending_block_size += n_written; | ||||
| 
 | ||||
|     auto n_written = bytes.copy_trimmed_to(pending_block().slice(m_pending_block_size)); | ||||
|     m_pending_block_size += n_written; | ||||
|         if (m_pending_block_size == block_size) | ||||
|             TRY(flush()); | ||||
| 
 | ||||
|     if (m_pending_block_size == block_size) | ||||
|         TRY(flush()); | ||||
| 
 | ||||
|     return n_written + TRY(write(bytes.slice(n_written))); | ||||
|         bytes = bytes.slice(n_written); | ||||
|         total_written += n_written; | ||||
|     } | ||||
|     return total_written; | ||||
| } | ||||
| 
 | ||||
| bool DeflateCompressor::is_eof() const | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nico Weber
						Nico Weber