Serenity Operating System

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.

authored by

Nico Weber and committed by
Brian Gianforcaro
dfb45705 e26aebca

+10 -8
+10 -8
Userland/Libraries/LibCompress/Deflate.cpp
··· 477 477 { 478 478 VERIFY(!m_finished); 479 479 480 - if (bytes.size() == 0) 481 - return 0; // recursion base case 482 - 483 - auto n_written = bytes.copy_trimmed_to(pending_block().slice(m_pending_block_size)); 484 - m_pending_block_size += n_written; 480 + size_t total_written = 0; 481 + while (!bytes.is_empty()) { 482 + auto n_written = bytes.copy_trimmed_to(pending_block().slice(m_pending_block_size)); 483 + m_pending_block_size += n_written; 485 484 486 - if (m_pending_block_size == block_size) 487 - TRY(flush()); 485 + if (m_pending_block_size == block_size) 486 + TRY(flush()); 488 487 489 - return n_written + TRY(write(bytes.slice(n_written))); 488 + bytes = bytes.slice(n_written); 489 + total_written += n_written; 490 + } 491 + return total_written; 490 492 } 491 493 492 494 bool DeflateCompressor::is_eof() const