readString(): Read directly into std::string
When reading a huge string, this halves memory consumption. (Strictly speaking, this appears only valid in C++17, but who cares...)
This commit is contained in:
		
							parent
							
								
									07a0b8ca67
								
							
						
					
					
						commit
						374908726b
					
				
					 1 changed files with 3 additions and 3 deletions
				
			
		|  | @ -207,10 +207,10 @@ size_t readString(unsigned char * buf, size_t max, Source & source) | |||
| string readString(Source & source) | ||||
| { | ||||
|     auto len = readNum<size_t>(source); | ||||
|     auto buf = std::make_unique<unsigned char[]>(len); | ||||
|     source(buf.get(), len); | ||||
|     std::string res(len, 0); | ||||
|     source((unsigned char*) res.data(), len); | ||||
|     readPadding(len, source); | ||||
|     return string((char *) buf.get(), len); | ||||
|     return res; | ||||
| } | ||||
| 
 | ||||
| Source & operator >> (Source & in, string & s) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue