mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-30 19:57:10 +01:00 
			
		
		
		
	Optimize SourceLineInfo::operator< with short-circuiting
In case of 2 instances of SourceLineInfo constructed in the same file, they will have the same `file` pointer (even at O0). Thus, we can check if they are equal before calling potentially pointless `strcmp`.
This commit is contained in:
		| @@ -22,7 +22,9 @@ namespace Catch { | ||||
|         return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); | ||||
|     } | ||||
|     bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept { | ||||
|         return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0)); | ||||
|         // We can assume that the same file will usually have the same pointer. | ||||
|         // Thus, if the pointers are the same, there is no point in calling the strcmp | ||||
|         return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0)); | ||||
|     } | ||||
|  | ||||
|     std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský