浏览代码

* first (modified, added a comment) patch by Rika to improve generic Index*, part of #39996

florian 2 年之前
父节点
当前提交
c1ec558d0a
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 12 6
      rtl/inc/generic.inc

+ 12 - 6
rtl/inc/generic.inc

@@ -358,7 +358,8 @@ begin
       begin
       begin
         if unaligned(psrc^)=b then
         if unaligned(psrc^)=b then
           begin
           begin
-            result:=psrc-pword(@buf);
+            { the result is always >=0 so avoid handling of negative values }
+            result:=PtrUint(pointer(psrc)-pointer(@buf)) div sizeof(word);
             exit;
             exit;
           end;
           end;
         inc(psrc);
         inc(psrc);
@@ -369,7 +370,8 @@ begin
       begin
       begin
         if psrc^=b then
         if psrc^=b then
           begin
           begin
-            result:=psrc-pword(@buf);
+            { the result is always >=0 so avoid handling of negative values }
+            result:=PtrUint(pointer(psrc)-pointer(@buf)) div sizeof(word);
             exit;
             exit;
           end;
           end;
         inc(psrc);
         inc(psrc);
@@ -399,7 +401,8 @@ begin
       begin
       begin
         if unaligned(psrc^)=b then
         if unaligned(psrc^)=b then
           begin
           begin
-            result:=psrc-pdword(@buf);
+            { the result is always >=0 so avoid handling of negative values }
+            result:=PtrUint(pointer(psrc)-pointer(@buf)) div sizeof(DWord);
             exit;
             exit;
           end;
           end;
         inc(psrc);
         inc(psrc);
@@ -410,7 +413,8 @@ begin
       begin
       begin
         if psrc^=b then
         if psrc^=b then
           begin
           begin
-            result:=psrc-pdword(@buf);
+            { the result is always >=0 so avoid handling of negative values }
+            result:=PtrUint(pointer(psrc)-pointer(@buf)) div sizeof(DWord);
             exit;
             exit;
           end;
           end;
         inc(psrc);
         inc(psrc);
@@ -440,7 +444,8 @@ begin
       begin
       begin
         if unaligned(psrc^)=b then
         if unaligned(psrc^)=b then
           begin
           begin
-            result:=psrc-pqword(@buf);
+            { the result is always >=0 so avoid handling of negative values }
+            result:=PtrUint(pointer(psrc)-pointer(@buf)) div sizeof(QWord);
             exit;
             exit;
           end;
           end;
         inc(psrc);
         inc(psrc);
@@ -451,7 +456,8 @@ begin
       begin
       begin
         if psrc^=b then
         if psrc^=b then
           begin
           begin
-            result:=psrc-pqword(@buf);
+            { the result is always >=0 so avoid handling of negative values }
+            result:=PtrUint(pointer(psrc)-pointer(@buf)) div sizeof(QWord);
             exit;
             exit;
           end;
           end;
         inc(psrc);
         inc(psrc);