فهرست منبع

Avoid multiple threadvar lookups when querying the current TThread. Inspired by Michael Schnell.

rtl/objpas/classes/classes.inc, TThread.GetCurrentThread:
	* instead of checking CurrentThreadVar and reading it again afterwards we read it first into Result and check this value; this way we have one read access in the normal case and one read and one write access in the worst case

git-svn-id: trunk@23706 -
svenbarth 12 سال پیش
والد
کامیت
da7b24e242
1فایلهای تغییر یافته به همراه4 افزوده شده و 3 حذف شده
  1. 4 3
      rtl/objpas/classes/classes.inc

+ 4 - 3
rtl/objpas/classes/classes.inc

@@ -387,10 +387,11 @@ class function TThread.GetCurrentThread: TThread;
 begin
   { if this is the first time GetCurrentThread is called for an external thread
     we need to create a corresponding TExternalThread instance }
-  if not Assigned(CurrentThreadVar) then
-    CurrentThreadVar := TExternalThread.Create;
-
   Result := CurrentThreadVar;
+  if not Assigned(Result) then begin
+    Result := TExternalThread.Create;
+    CurrentThreadVar := Result;
+  end;
 end;