Author: igorz
Date: 2007-12-09 08:29:10 -0500 (Sun, 09 Dec 2007)
New Revision: 91001

Modified:
   
branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/ObjectStateFormatter.cs
   branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs
Log:
performance optimization in Save/Load state

Modified: 
branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/ObjectStateFormatter.cs
===================================================================
--- 
branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/ObjectStateFormatter.cs
    2007-12-09 13:26:17 UTC (rev 91000)
+++ 
branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/ObjectStateFormatter.cs
    2007-12-09 13:29:10 UTC (rev 91001)
@@ -153,6 +153,10 @@
                                return "";
 #endif
                        byte [] buffer = Convert.FromBase64String (inputString);
+                       return DeserializeInternal (buffer);
+               }
+
+               internal object DeserializeInternal(byte [] buffer) {
                        int length;
                        if (buffer == null || (length = buffer.Length) == 0)
                                throw new ArgumentNullException ("inputString");
@@ -169,11 +173,16 @@
                        return Deserialize (ms);
                }
                
-               public string Serialize (object stateGraph)
-               {
+               public string Serialize (object stateGraph) {
                        if (stateGraph == null)
                                return "";
-                       
+                       int length;
+                       byte [] buffer = SerializeInternal (stateGraph, out 
length);
+                       return Convert.ToBase64String (buffer, 0, length);
+               }
+
+               internal byte[] SerializeInternal(object stateGraph, out int 
length) {
+
                        MemoryStream ms = new MemoryStream ();
                        Stream output = ms;
 #if NET_2_0
@@ -198,7 +207,9 @@
                                }
                                
                        }
-                       return Convert.ToBase64String (ms.GetBuffer (), 0, 
(int) ms.Length);
+
+                       length = (int) ms.Length;
+                       return ms.GetBuffer ();
                }
                
                public void Serialize (Stream outputStream, object stateGraph)

Modified: branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs
===================================================================
--- branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs        
2007-12-09 13:26:17 UTC (rev 91000)
+++ branches/mainsoft/JSF/mcs/class/System.Web/System.Web.UI/Page.jsf.cs        
2007-12-09 13:29:10 UTC (rev 91001)
@@ -152,7 +152,18 @@
 #if DEBUG
                        Console.WriteLine ("processSaveState");
 #endif
-                       return new object [] { _state, GetValidatorsState () };
+                       object state = new Pair (_state, GetValidatorsState ());
+                       if (getFacesContext ().getApplication 
().getStateManager ().isSavingStateInClient (getFacesContext ())) {
+                               int length;
+                               byte [] buffer = new ObjectStateFormatter 
(this).SerializeInternal (state, out length);
+                               if (buffer.Length != length) {
+                                       byte [] trimmedBuffer = new byte 
[length];
+                                       Array.Copy (buffer, trimmedBuffer, 
length);
+                                       buffer = trimmedBuffer;
+                               }
+                               state = vmw.common.TypeUtils.ToSByteArray 
(buffer);
+                       }
+                       return state;
                }
 
                public override void processRestoreState (FacesContext context, 
object state) {
@@ -161,8 +172,12 @@
 #endif
                        EnterThread (context);
                        try {
-                               _state = (Pair) ((object []) state) [0];
-                               _validatorsState = (bool []) ((object []) 
state) [1];
+                               if (getFacesContext ().getApplication 
().getStateManager ().isSavingStateInClient (getFacesContext ())) {
+                                       byte [] buffer = (byte []) 
vmw.common.TypeUtils.ToByteArray ((sbyte []) state);
+                                       state = new ObjectStateFormatter 
(this).DeserializeInternal (buffer);
+                               }
+                               _state = (Pair) ((Pair) state).First;
+                               _validatorsState = (bool []) ((Pair) 
state).Second;
                                RestorePageState ();
                        }
                        catch (Exception ex) {
@@ -323,7 +338,8 @@
                        }
 
                        public override void Save () {
-                               Page._state = new Pair (ViewState, 
ControlState);
+                               if (ViewState != null || ControlState != null)
+                                       Page._state = new Pair (ViewState, 
ControlState);
                        }
                }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to