@@ -660,22 +660,7 @@ bool Handler::preHandleRequest(Request* req, const String& key)
660660
661661 // Debug log: cursor received from client
662662 char cursorBuf[64 ];
663- int cursorLen = 0 ;
664- if (cursor == 0 ) {
665- cursorBuf[cursorLen++] = ' 0' ;
666- } else {
667- char temp[64 ];
668- int tempLen = 0 ;
669- __uint128_t c = cursor;
670- while (c > 0 ) {
671- temp[tempLen++] = ' 0' + (c % 10 );
672- c /= 10 ;
673- }
674- for (int i = tempLen - 1 ; i >= 0 ; i--) {
675- cursorBuf[cursorLen++] = temp[i];
676- }
677- }
678- cursorBuf[cursorLen] = ' \0 ' ;
663+ Util::uint128ToString (cursor, cursorBuf);
679664
680665 int groupIdx = (unsigned long )(cursor & Const::ServGroupMask);
681666 auto g = sp->getGroup (groupIdx);
@@ -701,22 +686,7 @@ bool Handler::preHandleRequest(Request* req, const String& key)
701686
702687 // Debug log: cursor to be sent to backend server
703688 char actualCursorBuf[64 ];
704- int actualLen = 0 ;
705- if (actualCursor == 0 ) {
706- actualCursorBuf[actualLen++] = ' 0' ;
707- } else {
708- char temp[64 ];
709- int tempLen = 0 ;
710- __uint128_t c = actualCursor;
711- while (c > 0 ) {
712- temp[tempLen++] = ' 0' + (c % 10 );
713- c /= 10 ;
714- }
715- for (int i = tempLen - 1 ; i >= 0 ; i--) {
716- actualCursorBuf[actualLen++] = temp[i];
717- }
718- }
719- actualCursorBuf[actualLen] = ' \0 ' ;
689+ Util::uint128ToString (actualCursor, actualCursorBuf);
720690
721691 logDebug (" h %d SCAN cursor from client: %s, group: %d, cursor to server: %s" ,
722692 id (), cursorBuf, groupIdx, actualCursorBuf);
@@ -901,23 +871,7 @@ void Handler::handleResponse(ConnectConnection* s, Request* req, Response* res)
901871 if ((p = strchr (p, ' *' )) != nullptr ) {
902872 // Convert 128-bit integer to string
903873 char buf[64 ]; // 128-bit needs at most 39 decimal digits
904- int n = 0 ;
905- if (cursor == 0 ) {
906- buf[n++] = ' 0' ;
907- } else {
908- char temp[64 ];
909- int tempLen = 0 ;
910- __uint128_t c = cursor;
911- while (c > 0 ) {
912- temp[tempLen++] = ' 0' + (c % 10 );
913- c /= 10 ;
914- }
915- // Reverse digits (extracted from low to high)
916- for (int i = tempLen - 1 ; i >= 0 ; i--) {
917- buf[n++] = temp[i];
918- }
919- }
920- buf[n] = ' \0 ' ;
874+ int n = Util::uint128ToString (cursor, buf);
921875
922876 // Debug log: cursor to be sent to client
923877 logDebug (" h %d SCAN cursor from server: %s, group: %d, cursor to client: %s" ,
0 commit comments