Browse code

core: added q_memrchr(...)

- reverse search for char in a buffer

Daniel-Constantin Mierla authored on 19/08/2012 10:52:51
Showing 1 changed files
... ...
@@ -432,7 +432,7 @@ static inline char* ushort2str(unsigned short u)
432 432
 
433 433
 
434 434
 
435
-/* faster memchr version */
435
+/* fast memchr version */
436 436
 static inline char* q_memchr(char* p, int c, unsigned int size)
437 437
 {
438 438
 	char* end;
... ...
@@ -443,7 +443,20 @@ static inline char* q_memchr(char* p, int c, unsigned int size)
443 443
 	}
444 444
 	return 0;
445 445
 }
446
-	
446
+
447
+
448
+/* fast reverse char search */
449
+
450
+static inline char* q_memrchr(char* p, int c, unsigned int size)
451
+{
452
+	char* end;
453
+
454
+	end=p+size-1;
455
+	for(;end>=p;end--) {
456
+		if (*end==(unsigned char)c) return end;
457
+	}
458
+	return 0;
459
+}
447 460
 
448 461
 /* returns -1 on error, 1! on success (consistent with int2reverse_hex) */
449 462
 inline static int reverse_hex2int( char *c, int len, unsigned int* res)