From e97fb23218734d1fbda87eedd7659235777a69ae Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Sat, 19 Nov 2011 10:02:20 -0500
Subject: [PATCH] Make LLSD diagnostic methods conditional on LLSD_DEBUG_INFO.
 This establishes that there are no viewer-side unit tests relying on these
 methods. The point is to try to clean up the LLSD public API. In the same
 vein, remove from LLSD public API a diagnostic method which is nothing more
 than an implementation detail for the corresponding LLSD::Impl method. The
 same effect can be achieved by making LLSD::Impl a friend of LLSD, moving the
 method with the messy signature (classic-C arrays!) into LLSD::Impl itself.

---
 indra/llcommon/llsd.cpp | 19 ++++++++++++++-----
 indra/llcommon/llsd.h   | 14 +++++++++++++-
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp
index 3fa08aee8d1..1bd5d06d299 100644
--- a/indra/llcommon/llsd.cpp
+++ b/indra/llcommon/llsd.cpp
@@ -148,6 +148,13 @@ class LLSD::Impl
 
 	virtual void dumpStats() const;
 	virtual void calcStats(S32 type_counts[], S32 share_counts[]) const;
+	// Container subclasses contain LLSD objects, rather than directly
+	// containing Impl objects. This helper forwards through LLSD.
+	void calcStats(const LLSD& llsd, S32 type_counts[], S32 share_counts[]) const
+	{
+		safe(llsd.impl).calcStats(type_counts, share_counts);
+	}
+
 
 	static const LLSD& undef();
 	
@@ -459,7 +466,7 @@ namespace
 		while (iter != endMap())
 		{
 			//std::cout << "  " << (*iter).first << ": " << (*iter).second << std::endl;
-			(*iter).second.calcStats(type_counts, share_counts);
+			Impl::calcStats((*iter).second, type_counts, share_counts);
 			iter++;
 		}
 
@@ -606,7 +613,7 @@ namespace
 		LLSD::array_const_iterator iter = beginArray();
 		while (iter != endArray())
 		{	// Add values for all items held in the array
-			(*iter).calcStats(type_counts, share_counts);
+			Impl::calcStats((*iter), type_counts, share_counts);
 			iter++;
 		}
 
@@ -802,7 +809,7 @@ void LLSD::clear()						{ Impl::assignUndefined(impl); }
 
 LLSD::Type LLSD::type() const			{ return safe(impl).type(); }
 
-// Scaler Constructors
+// Scalar Constructors
 LLSD::LLSD(Boolean v) : impl(0)			{ ALLOC_LLSD_OBJECT;	assign(v); }
 LLSD::LLSD(Integer v) : impl(0)			{ ALLOC_LLSD_OBJECT;	assign(v); }
 LLSD::LLSD(Real v) : impl(0)			{ ALLOC_LLSD_OBJECT;	assign(v); }
@@ -894,8 +901,10 @@ LLSD&		LLSD::operator[](Integer i)
 const LLSD& LLSD::operator[](Integer i) const
 										{ return safe(impl).ref(i); }
 
+#ifdef LLSD_DEBUG_INFO
 U32 LLSD::allocationCount()				{ return Impl::sAllocationCount; }
 U32 LLSD::outstandingCount()			{ return Impl::sOutstandingCount; }
+#endif
 
 static const char *llsd_dump(const LLSD &llsd, bool useXMLFormat)
 {
@@ -947,9 +956,9 @@ LLSD::array_const_iterator	LLSD::endArray() const	{ return safe(impl).endArray()
 
 
 // Diagnostic dump of contents in an LLSD object
+#ifdef LLSD_DEBUG_INFO
 void LLSD::dumpStats()	const						{ safe(impl).dumpStats();	}
-void LLSD::calcStats(S32 type_counts[], S32 share_counts[]) const
-													{ safe(impl).calcStats(type_counts, share_counts);	}
+#endif
 
 // static
 std::string		LLSD::typeString(Type type)
diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h
index 80c3e9e7b58..3519b134c20 100644
--- a/indra/llcommon/llsd.h
+++ b/indra/llcommon/llsd.h
@@ -387,13 +387,20 @@ class LL_COMMON_API LLSD
 		class Impl;
 private:
 		Impl* impl;
+		friend class LLSD::Impl;
 	//@}
 	
 	/** @name Unit Testing Interface */
 	//@{
 public:
+#ifdef LLSD_DEBUG_INFO
+		/// @warn THESE COUNTS WILL NOT BE ACCURATE IN A MULTI-THREADED
+		/// ENVIRONMENT.
+		///
+		/// These counts track LLSD::Impl (hidden) objects.
 		static U32 allocationCount();	///< how many Impls have been made
 		static U32 outstandingCount();	///< how many Impls are still alive
+#endif
 	//@}
 
 private:
@@ -407,12 +414,17 @@ class LL_COMMON_API LLSD
 	//@}
 
 public:
+#ifdef LLSD_DEBUG_INFO
 	void			dumpStats() const;					// Output information on object and usage
-	void			calcStats(S32 type_counts[], S32 share_counts[]) const;		// Calculate the number of LLSD objects used by this value
+#endif
 
 	static std::string		typeString(Type type);		// Return human-readable type as a string
 
 #ifdef LLSD_DEBUG_INFO
+	/// @warn THESE COUNTS WILL NOT BE ACCURATE IN A MULTI-THREADED
+	/// ENVIRONMENT.
+	///
+	/// These counts track LLSD (public) objects.
 	static S32		sLLSDAllocationCount;		// Number of LLSD objects ever created
 	static S32		sLLSDNetObjects;			// Number of LLSD objects that exist
 #endif
-- 
GitLab