mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:12:45 +00:00 
			
		
		
		
	KBuffer: Add set_size() and LogStream operator<<
It will be useful to be able to set the "public" size of a KBuffer. It can still have a different amount of memory allocated internally.
This commit is contained in:
		
							parent
							
								
									da6c8fe3f8
								
							
						
					
					
						commit
						f58b0c245d
					
				
					 1 changed files with 14 additions and 0 deletions
				
			
		|  | @ -11,6 +11,7 @@ | |||
| // severely limited kmalloc heap.
 | ||||
| 
 | ||||
| #include <AK/Assertions.h> | ||||
| #include <AK/LogStream.h> | ||||
| #include <Kernel/VM/MemoryManager.h> | ||||
| #include <Kernel/VM/Region.h> | ||||
| 
 | ||||
|  | @ -35,6 +36,12 @@ public: | |||
|     size_t size() const { return m_size; } | ||||
|     size_t capacity() const { return m_region->size(); } | ||||
| 
 | ||||
|     void set_size(size_t size) | ||||
|     { | ||||
|         ASSERT(size <= capacity()); | ||||
|         m_size = size; | ||||
|     } | ||||
| 
 | ||||
| private: | ||||
|     explicit KBufferImpl(NonnullRefPtr<Region>&& region, size_t size) | ||||
|         : m_size(size) | ||||
|  | @ -63,6 +70,8 @@ public: | |||
|     size_t size() const { return m_impl->size(); } | ||||
|     size_t capacity() const { return m_impl->size(); } | ||||
| 
 | ||||
|     void set_size(size_t size) { m_impl->set_size(size); } | ||||
| 
 | ||||
|     const KBufferImpl& impl() const { return m_impl; } | ||||
| 
 | ||||
|     KBuffer(const ByteBuffer& buffer) | ||||
|  | @ -78,3 +87,8 @@ private: | |||
| 
 | ||||
|     NonnullRefPtr<KBufferImpl> m_impl; | ||||
| }; | ||||
| 
 | ||||
| inline const LogStream& operator<<(const LogStream& stream, const KBuffer& value) | ||||
| { | ||||
|     return stream << StringView(value.data(), value.size()); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling