Ver Fonte

xbakes, we even avoid another array copy since httpRequest.InputStream is a memorystream with origin = 0

UbitUmarov há 3 anos atrás
pai
commit
0957317790

+ 2 - 2
OpenSim/Server/Handlers/BakedTextures/XBakes.cs

@@ -83,7 +83,7 @@ namespace OpenSim.Server.Handlers.BakedTextures
             return new byte[0];
         }
 
-        public void Store(string id, byte[] data)
+        public void Store(string id, byte[] data, int dataLength)
         {
             string file = HashToFile(id);
             string diskFile = Path.Combine(m_FSBase, file);
@@ -92,7 +92,7 @@ namespace OpenSim.Server.Handlers.BakedTextures
 
             File.Delete(diskFile);
             using (FileStream fs = File.Create(diskFile))
-                fs.Write(data, 0, data.Length);
+                fs.Write(data, 0, dataLength);
         }
 
         private void HandleDeleteBakes(string module, string[] args)

+ 7 - 3
OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs

@@ -115,9 +115,13 @@ namespace OpenSim.Server.Handlers.BakedTextures
 
             if (p.Length == 0)
                 return;
-            byte[] data = ((MemoryStream)httpRequest.InputStream).ToArray();
-            httpRequest.InputStream.Dispose();
-            m_BakesService.Store(p[0], data);
+            // httpRequest.InputStream is a memorystream with origin = 0
+            // so no need to copy to another array
+            MemoryStream ms = (MemoryStream)httpRequest.InputStream;
+            int len = (int)ms.Length;
+            byte[] data = ms.GetBuffer();
+            httpRequest.InputStream.Dispose(); // the buffer stays in data
+            m_BakesService.Store(p[0], data, len);
         }
 
         public string[] SplitParams(string path)

+ 1 - 1
OpenSim/Services/Interfaces/IBakedTextureService.cs

@@ -33,6 +33,6 @@ namespace OpenSim.Services.Interfaces
     public interface IBakedTextureService
     {
         byte[] Get(string id);
-        void Store(string id, byte[] data);
+        void Store(string id, byte[] data, int datalenght);
     }
 }