From d87d8338e6e7cf6b1567d38f87229307d71fdee3 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Wed, 9 Jun 2021 18:39:41 -0400
Subject: [PATCH] Add variant of unpackVolumeFaces that accepts a char* buffer
 to avoid additional malloc for input/output

---
 indra/llmath/llvolume.cpp | 20 +++++++++++++++++++-
 indra/llmath/llvolume.h   |  5 +++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 553b26f3476..b98ce39da85 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -2374,7 +2374,25 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
 		LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL;
 		return false;
 	}
-	
+	return unpackVolumeFacesInternal(mdl);
+}
+
+bool LLVolume::unpackVolumeFaces(U8* in_data, S32 size)
+{
+	//input stream is now pointing at a zlib compressed block of LLSD
+	//decompress block
+	LLSD mdl;
+	U32 uzip_result = LLUZipHelper::unzip_llsd(mdl, in_data, size);
+	if (uzip_result != LLUZipHelper::ZR_OK)
+	{
+		LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL;
+		return false;
+	}
+	return unpackVolumeFacesInternal(mdl);
+}
+
+bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl)
+{
 	{
 		U32 face_count = mdl.size();
 
diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h
index a927e65bbe3..0dcfa7844d9 100644
--- a/indra/llmath/llvolume.h
+++ b/indra/llmath/llvolume.h
@@ -1086,6 +1086,11 @@ class LLVolume : public LLRefCount
 	void createVolumeFaces();
 public:
 	bool unpackVolumeFaces(std::istream& is, S32 size);
+	bool unpackVolumeFaces(U8* in_data, S32 size);
+private:
+	bool unpackVolumeFacesInternal(const LLSD& mdl);
+
+public:
 
 	void setMeshAssetLoaded(BOOL loaded);
 	BOOL isMeshAssetLoaded();
-- 
GitLab