From a5b6142f6b53608769cfb3c33dbbbf3710b86d1b Mon Sep 17 00:00:00 2001 From: William Todd Stinson Date: Tue, 4 Dec 2012 16:51:03 -0800 Subject: Updating the comparison function to not use ascii-character comparison. This will give better sorting when the operator overriden comparators are used. --- indra/llprimitive/llmaterialid.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'indra/llprimitive/llmaterialid.cpp') diff --git a/indra/llprimitive/llmaterialid.cpp b/indra/llprimitive/llmaterialid.cpp index 5c810ddf12..590f5cd91f 100644 --- a/indra/llprimitive/llmaterialid.cpp +++ b/indra/llprimitive/llmaterialid.cpp @@ -137,7 +137,6 @@ LLSD LLMaterialID::asLLSD() const std::string LLMaterialID::asString() const { - std::string materialID(reinterpret_cast(get()), MATERIAL_ID_SIZE); std::string materialIDString; for (unsigned int i = 0U; i < static_cast(MATERIAL_ID_SIZE / sizeof(U32)); ++i) { @@ -145,7 +144,7 @@ std::string LLMaterialID::asString() const { materialIDString += "-"; } - const U32 *value = reinterpret_cast(&materialID.c_str()[i * sizeof(U32)]); + const U32 *value = reinterpret_cast(&get()[i * sizeof(U32)]); materialIDString += llformat("%08x", *value); } return materialIDString; @@ -159,10 +158,19 @@ void LLMaterialID::parseFromBinary (const LLSD::Binary& pMaterialID) void LLMaterialID::copyFromOtherMaterialID(const LLMaterialID& pOtherMaterialID) { - memcpy(mID, pOtherMaterialID.mID, MATERIAL_ID_SIZE * sizeof(U8)); + memcpy(mID, pOtherMaterialID.get(), MATERIAL_ID_SIZE * sizeof(U8)); } int LLMaterialID::compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const { - return memcmp(mID, pOtherMaterialID.mID, MATERIAL_ID_SIZE * sizeof(U8)); + int retVal = 0; + + for (unsigned int i = 0U; (retVal == 0) && (i < static_cast(MATERIAL_ID_SIZE / sizeof(U32))); ++i) + { + const U32 *thisValue = reinterpret_cast(&get()[i * sizeof(U32)]); + const U32 *otherValue = reinterpret_cast(&pOtherMaterialID.get()[i * sizeof(U32)]); + retVal = ((*thisValue < *otherValue) ? -1 : ((*thisValue > *otherValue) ? 1 : 0)); + } + + return retVal; } -- cgit v1.2.3