Commit in reactos on MAIN
include/win32k/region.h+4-11.19 -> 1.20
subsys/win32k/objects/region.c+42-261.45 -> 1.46
+46-27
2 modified files
Most regions (> 95% in testing) consist of only 1 rectangle. Add a single
rectangle buffer to ROSRGNDATA to avoid dynamic memory allocation

reactos/include/win32k
region.h 1.19 -> 1.20
diff -u -r1.19 -r1.20
--- region.h	22 Mar 2004 20:14:28 -0000	1.19
+++ region.h	3 Apr 2004 20:36:55 -0000	1.20
@@ -7,7 +7,10 @@
 /* Internal region data. Can't use RGNDATA structure because buffer is allocated statically */
 typedef struct _ROSRGNDATA {
   RGNDATAHEADER rdh;
-  char*          Buffer;
+  char*         Buffer;
+  RECT          BuiltInRect;   /* Testing shows that > 95% of all regions have only 1 rect.
+                                  Including that here saves us from having to do another
+                                  allocation */
 } ROSRGNDATA, *PROSRGNDATA, *LPROSRGNDATA;
 
 

reactos/subsys/win32k/objects
region.c 1.45 -> 1.46
diff -u -r1.45 -r1.46
--- region.c	23 Mar 2004 17:07:41 -0000	1.45
+++ region.c	3 Apr 2004 20:36:56 -0000	1.46
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: region.c,v 1.45 2004/03/23 17:07:41 gvg Exp $ */
+/* $Id: region.c,v 1.46 2004/04/03 20:36:56 gvg Exp $ */
 #undef WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <ddk/ntddk.h>
@@ -78,7 +78,8 @@
 		    return 0;
 		RtlCopyMemory( temp, *firstrect, reg->rdh.nRgnSize );
 		reg->rdh.nRgnSize *= 2;
-		ExFreePool( *firstrect );
+		if (*firstrect != &reg->BuiltInRect)
+		    ExFreePool( *firstrect );
 		*firstrect = temp;
 		*rect = (*firstrect)+reg->rdh.nCount;
     }
@@ -141,7 +142,7 @@
 	  if( !temp )
 		return FALSE;
 
-	  if( dst->Buffer )
+	  if( dst->Buffer && dst->Buffer != (char *) &dst->BuiltInRect )
 	  	ExFreePool( dst->Buffer );	//free the old buffer
 	  dst->Buffer = temp;
       dst->rdh.nRgnSize = src->rdh.nCount * sizeof(RECT);  //size of region buffer
@@ -216,7 +217,7 @@
     }
     else{
       xrect = ExAllocatePoolWithTag(PagedPool, rgnSrc->rdh.nCount * sizeof(RECT), TAG_REGION);
-	  if( rgnDst->Buffer )
+	  if( rgnDst->Buffer && rgnDst->Buffer != (char *) &rgnDst->BuiltInRect )
 	  	ExFreePool( rgnDst->Buffer ); //free the old buffer. will be assigned to xrect below.
 	}
 
@@ -279,7 +280,7 @@
       if(!temp)
 	      return FALSE;
 
-	  if( rgnDst->Buffer )
+	  if( rgnDst->Buffer && rgnDst->Buffer != (char *) &rgnDst->BuiltInRect )
 	  	ExFreePool( rgnDst->Buffer ); //free the old buffer
       (PRECT)rgnDst->Buffer = temp;
       rgnDst->rdh.nCount = i;
@@ -817,7 +818,8 @@
 			else{
 				newReg->rdh.nRgnSize = newReg->rdh.nCount*sizeof(RECT);
 				RtlCopyMemory( newReg->Buffer, prev_rects, newReg->rdh.nRgnSize );
-				ExFreePool( prev_rects );
+				if (prev_rects != &newReg->BuiltInRect)
+					ExFreePool( prev_rects );
 			}
 		}
 		else
@@ -827,7 +829,8 @@
 		     * the region is empty
 		     */
 		    newReg->rdh.nRgnSize = sizeof(RECT);
-		    ExFreePool( newReg->Buffer );
+		    if (newReg->Buffer != (char *) &newReg->BuiltInRect)
+			ExFreePool( newReg->Buffer );
 		    newReg->Buffer = ExAllocatePoolWithTag( PagedPool, sizeof(RECT), TAG_REGION );
 			ASSERT( newReg->Buffer );
 		}
@@ -838,7 +841,8 @@
 	else
 		newReg->rdh.iType = (newReg->rdh.nCount > 1)? COMPLEXREGION : SIMPLEREGION;
 
-	ExFreePool( oldRects );
+	if (oldRects != &newReg->BuiltInRect)
+		ExFreePool( oldRects );
     return;
 }
 
@@ -1473,33 +1477,45 @@
   PROSRGNDATA pReg;
   BOOL bRet;
 
-  if((hReg = (HRGN)GDIOBJ_AllocObj(sizeof(ROSRGNDATA), GDI_OBJECT_TYPE_REGION,
-                                   (GDICLEANUPPROC) RGNDATA_InternalDelete))){
-	if( (pReg = RGNDATA_LockRgn(hReg)) ){
-
-      if ((pReg->Buffer = ExAllocatePoolWithTag(PagedPool, n * sizeof(RECT), TAG_REGION))){
-      	EMPTY_REGION(pReg);
-      	pReg->rdh.dwSize = sizeof(RGNDATAHEADER);
-      	pReg->rdh.nCount = n;
-      	pReg->rdh.nRgnSize = n*sizeof(RECT);
+  if ((hReg = (HRGN) GDIOBJ_AllocObj(sizeof(ROSRGNDATA), GDI_OBJECT_TYPE_REGION,
+                                     (GDICLEANUPPROC) RGNDATA_InternalDelete)))
+    {
+      if (NULL != (pReg = RGNDATA_LockRgn(hReg)))
+        {
+          if (1 == n)
+            {
+              pReg->Buffer = (char *) &pReg->BuiltInRect;
+            }
+          else
+            {
+              pReg->Buffer = ExAllocatePoolWithTag(PagedPool, n * sizeof(RECT), TAG_REGION);
+            }
+          if (NULL != pReg->Buffer)
+            {
+              EMPTY_REGION(pReg);
+              pReg->rdh.dwSize = sizeof(RGNDATAHEADER);
+              pReg->rdh.nCount = n;
+              pReg->rdh.nRgnSize = n*sizeof(RECT);
 
-        bRet = RGNDATA_UnlockRgn(hReg);
-        ASSERT(bRet);
+              bRet = RGNDATA_UnlockRgn(hReg);
+              ASSERT(bRet);
 
-      	return hReg;
-	  }
+              return hReg;
+            }
+        }
+      else
+        {
+          RGNDATA_FreeRgn(hReg);
+        }
+    }
 
-	}
-	else
-		RGNDATA_FreeRgn(hReg);
-  }
   return NULL;
 }
 
 BOOL FASTCALL RGNDATA_InternalDelete( PROSRGNDATA pRgn )
 {
   ASSERT(pRgn);
-  if(pRgn->Buffer)
+  if(pRgn->Buffer && pRgn->Buffer != (char *) &pRgn->BuiltInRect)
     ExFreePool(pRgn->Buffer);
   return TRUE;
 }
CVSspam 0.2.8