dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/Xsharp HandleMap.cs, NONE, 1.1 Display.cs,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/Xsharp HandleMap.cs, NONE, 1.1 Display.cs, 1.11, 1.12 Drawable.cs, 1.1, 1.2 EmbeddedApplication.cs, 1.5, 1.6 InputOnlyWidget.cs, 1.4, 1.5 RootWindow.cs, 1.3, 1.4 Widget.cs, 1.8, 1.9
Date: Fri, 21 Nov 2003 01:15:35 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv32188/Xsharp

Modified Files:
        Display.cs Drawable.cs EmbeddedApplication.cs 
        InputOnlyWidget.cs RootWindow.cs Widget.cs 
Added Files:
        HandleMap.cs 
Log Message:


Speed up Xsharp event dispatching by using a more efficient handle
to widget mapping table.


Index: InputOnlyWidget.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/InputOnlyWidget.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** InputOnlyWidget.cs  23 Jun 2003 01:04:21 -0000      1.4
--- InputOnlyWidget.cs  21 Nov 2003 01:15:33 -0000      1.5
***************
*** 669,674 ****
                                        {
                                                // Dispatch a widget enter 
event.
!                                               Widget child = 
(Widget)(dpy.handleMap
!                                                       
[(int)(xevent.xcrossing.subwindow)]);
                                                OnEnter(child,
                                                            xevent.xcrossing.x,
--- 669,674 ----
                                        {
                                                // Dispatch a widget enter 
event.
!                                               Widget child = dpy.handleMap
!                                                       
[xevent.xcrossing.subwindow];
                                                OnEnter(child,
                                                            xevent.xcrossing.x,
***************
*** 683,688 ****
                                        {
                                                // Dispatch a widget leave 
event.
!                                               Widget child = 
(Widget)(dpy.handleMap
!                                                       
[(int)(xevent.xcrossing.subwindow)]);
                                                OnLeave(child,
                                                            xevent.xcrossing.x,
--- 683,688 ----
                                        {
                                                // Dispatch a widget leave 
event.
!                                               Widget child = dpy.handleMap
!                                                       
[xevent.xcrossing.subwindow];
                                                OnLeave(child,
                                                            xevent.xcrossing.x,

Index: Drawable.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Drawable.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Drawable.cs 28 May 2003 04:17:53 -0000      1.1
--- Drawable.cs 21 Nov 2003 01:15:33 -0000      1.2
***************
*** 66,70 ****
                                        dpy.Lock();
                                        this.handle = (Xlib.Drawable)handle;
!                                       dpy.handleMap[(int)handle] = this;
                                }
                                finally
--- 66,70 ----
                                        dpy.Lock();
                                        this.handle = (Xlib.Drawable)handle;
!                                       dpy.handleMap[handle] = (Widget)this;
                                }
                                finally

Index: RootWindow.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/RootWindow.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** RootWindow.cs       14 Jun 2003 09:50:51 -0000      1.3
--- RootWindow.cs       21 Nov 2003 01:15:33 -0000      1.4
***************
*** 48,54 ****
                                if(dpy.handleMap == null)
                                {
!                                       dpy.handleMap = new Hashtable();
                                }
!                               dpy.handleMap[(int)handle] = this;
  
                                // Adjust the root window object to match the 
screen state.
--- 48,54 ----
                                if(dpy.handleMap == null)
                                {
!                                       dpy.handleMap = new HandleMap();
                                }
!                               dpy.handleMap[handle] = this;
  
                                // Adjust the root window object to match the 
screen state.

Index: EmbeddedApplication.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/EmbeddedApplication.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** EmbeddedApplication.cs      1 Nov 2003 03:30:23 -0000       1.5
--- EmbeddedApplication.cs      21 Nov 2003 01:15:33 -0000      1.6
***************
*** 805,809 ****
                                        embedParent = parent;
                                        handle = (Xlib.Drawable)group;
!                                       dpy.handleMap[(int)handle] = this;
                                }
  
--- 805,809 ----
                                        embedParent = parent;
                                        handle = (Xlib.Drawable)group;
!                                       dpy.handleMap[(Xlib.Window)handle] = 
this;
                                }
  

Index: Widget.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Widget.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Widget.cs   1 Nov 2003 03:30:23 -0000       1.8
--- Widget.cs   21 Nov 2003 01:15:33 -0000      1.9
***************
*** 128,132 ****
                                if(handle != Xlib.Drawable.Zero)
                                {
!                                       dpy.handleMap.Remove((int)handle);
                                }
                                if(this is InputOutputWidget)
--- 128,132 ----
                                if(handle != Xlib.Drawable.Zero)
                                {
!                                       
dpy.handleMap.Remove((Xlib.Window)handle);
                                }
                                if(this is InputOutputWidget)

--- NEW FILE: HandleMap.cs ---
/*
 * HandleMap.cs - Quick hash table for mapping window handles.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace Xsharp
{

using System;

// This class is a lot more efficient than "Hashtable" when it comes
// to mapping window handles to widget objects.

internal class HandleMap
{
        // Internal state.
        private HandleInfo[] handles;

        // Size of the hash table: must be a power of two.  Handles are 
allocated
        // sequentially by Xlib, so there is little point in using a prime 
number
        // for the hash table size, and powers of two are more efficient.
        private const int HashSize = 1024;

        // Information about a handle in the main part of the table.
        private struct HandleInfo
        {
                public Xlib.Window window;
                public Widget widget;
                public HandleOverflowInfo overflow;

        }; // struct HandleInfo

        // Information about a handle in the overflow part of the table.
        private class HandleOverflowInfo
        {
                public Xlib.Window window;
                public Widget widget;
                public HandleOverflowInfo overflow;

        }; // class HandleOverflowInfo

        // Constructor.
        public HandleMap()
                        {
                                handles = new HandleInfo [HashSize];
                        }

        // Get or set a member within this handle map.
        public Widget this[Xlib.Window window]
                        {
                                get
                                {
                                        // Look in the main part of the table.
                                        int hash = (((int)window) & (HashSize - 
1));
                                        if(handles[hash].window == window)
                                        {
                                                return handles[hash].widget;
                                        }

                                        // Look in the overflow part of the 
table.
                                        HandleOverflowInfo info = 
handles[hash].overflow;
                                        while(info != null)
                                        {
                                                if(info.window == window)
                                                {
                                                        return info.widget;
                                                }
                                                info = info.overflow;
                                        }

                                        // There is no widget registered with 
this handle.
                                        return null;
                                }
                                set
                                {
                                        // Look in the main part of the table.
                                        int hash = (((int)window) & (HashSize - 
1));
                                        if(handles[hash].window == window)
                                        {
                                                handles[hash].widget = value;
                                                return;
                                        }

                                        // Look in the overflow part of the 
table.
                                        HandleOverflowInfo info = 
handles[hash].overflow;
                                        while(info != null)
                                        {
                                                if(info.window == window)
                                                {
                                                        info.widget = value;
                                                        return;
                                                }
                                                info = info.overflow;
                                        }

                                        // Add to the main part of the table if 
it is empty.
                                        if(handles[hash].window == 
Xlib.Window.Zero)
                                        {
                                                handles[hash].window = window;
                                                handles[hash].widget = value;
                                                return;
                                        }

                                        // Add an overflow entry to the hash 
table.
                                        info = new HandleOverflowInfo();
                                        info.window = window;
                                        info.widget = value;
                                        info.overflow = handles[hash].overflow;
                                        handles[hash].overflow = info;
                                }
                        }

        // Remove an element from this handle map.
        public void Remove(Xlib.Window window)
                        {
                                // Look in the main part of the table.
                                int hash = (((int)window) & (HashSize - 1));
                                if(handles[hash].window == window)
                                {
                                        handles[hash].window = Xlib.Window.Zero;
                                        handles[hash].widget = null;
                                        return;
                                }

                                // Look in the overflow part of the table.
                                HandleOverflowInfo info = 
handles[hash].overflow;
                                while(info != null)
                                {
                                        if(info.window == window)
                                        {
                                                info.window = Xlib.Window.Zero;
                                                info.widget = null;
                                                return;
                                        }
                                        info = info.overflow;
                                }
                        }

} // class HandleMap

} // namespace Xsharp

Index: Display.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Display.cs,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Display.cs  31 Oct 2003 06:44:35 -0000      1.11
--- Display.cs  21 Nov 2003 01:15:33 -0000      1.12
***************
*** 49,53 ****
        private Xlib.Cursor[] cursors;
        internal Xlib.Time knownEventTime;
!       internal Hashtable handleMap;
        private static bool threadsInited;
        internal Xlib.Atom wmProtocols;
--- 49,53 ----
        private Xlib.Cursor[] cursors;
        internal Xlib.Time knownEventTime;
!       internal HandleMap handleMap;
        private static bool threadsInited;
        internal Xlib.Atom wmProtocols;
***************
*** 91,95 ****
                                if(handleMap == null)
                                {
!                                       handleMap = new Hashtable();
                                }
  
--- 91,95 ----
                                if(handleMap == null)
                                {
!                                       handleMap = new HandleMap();
                                }
  
***************
*** 746,750 ****
  
                                // Find the widget that should process the 
event.
!                               Widget widget = 
(Widget)(handleMap[(int)(xevent.window)]);
  
                                // Dispatch the event to the widget.
--- 746,750 ----
  
                                // Find the widget that should process the 
event.
!                               Widget widget = handleMap[xevent.window];
  
                                // Dispatch the event to the widget.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]