github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekatime/encode_private.go (about) 1 // Copyright © 2020. All rights reserved. 2 // Author: Ilya Stroy. 3 // Contacts: iyuryevich@pm.me, https://github.com/qioalice 4 // License: https://opensource.org/licenses/MIT 5 6 package ekatime 7 8 // batoi is atoi from ASCII string with 2 characters b1, b2. 9 // It allows to write algorithms to decode Date, Time, Timestamp from string 10 // faster up to 5x than using strconv.Atoi(). 11 func batoi(b1, b2 byte) (i int16, valid bool) { 12 if b2 = b2 - '0'; b2 > 9 { 13 return 0, false 14 } 15 i = int16(b2) 16 if b1 == '-' { 17 return -i, true 18 } 19 if b1 = b1 - '0'; b1 > 9 { 20 return 0, false 21 } 22 return int16(b1)*10 + i, true 23 }