Fix semdiff syntactic output
[hiphop-php.git] / hphp / util / fast_strtoll_base10.h
blob0b034181f25b3563f65bc1dbe138df944d5cf9ec
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_UTIL_FAST_STRTOLL_BASE10_H_
18 #define incl_HPHP_UTIL_FAST_STRTOLL_BASE10_H_
20 namespace HPHP {
22 // This a fast version of strtoll() specialized for base 10. This version
23 // does not skip leading white space. It does not check for overflow/underflow,
24 // in which case the return value becomes different from strtoll(3c) that
25 // sets the result to LLONG_MAX/LLONG_MIN and errno to ERANGE.
26 // This function never sets errno. Thus a caller is responsible for making
27 // sure the value fits in [LLONG_MIN, LLONG_MAX] range.
28 inline int64_t fast_strtoll_base10(const char* p) {
29 int64_t x = 0;
30 bool neg = false;
32 if (*p == '-') {
33 neg = true;
34 ++p;
35 } else if (*p == '+') {
36 ++p;
38 while (*p >= '0' && *p <= '9') {
39 x = (x * 10) + ('0' - *p);
40 ++p;
42 if (!neg) {
43 x = -x;
46 return x;
51 #endif