From c973e5060c3656494f2cd1366ad195e259406a2a Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 12 May 2014 13:56:44 +0200 Subject: [PATCH] Optimizations to DTSC::Scan when called with raw character pointers. --- lib/dtsc.h | 2 ++ lib/dtscmeta.cpp | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/dtsc.h b/lib/dtsc.h index fdbf984b..130c8310 100644 --- a/lib/dtsc.h +++ b/lib/dtsc.h @@ -73,6 +73,8 @@ namespace DTSC { Scan(char * pointer, size_t len); std::string toPrettyString(unsigned int indent = 0); Scan getMember(std::string indice); + Scan getMember(const char * indice); + Scan getMember(const char * indice, const unsigned int ind_len); Scan getIndice(unsigned int num); char getType(); diff --git a/lib/dtscmeta.cpp b/lib/dtscmeta.cpp index d6057658..e0eb2c5d 100644 --- a/lib/dtscmeta.cpp +++ b/lib/dtscmeta.cpp @@ -361,6 +361,12 @@ namespace DTSC { /// Returns an object representing the named indice of this object. /// Returns an invalid object if this indice doesn't exist or this isn't an object type. Scan Scan::getMember(std::string indice){ + return getMember(indice.data(), indice.size()); + } + + /// Returns an object representing the named indice of this object. + /// Returns an invalid object if this indice doesn't exist or this isn't an object type. + Scan Scan::getMember(const char * indice, const unsigned int ind_len){ if (getType() != DTSC_OBJ && getType() != DTSC_CON){ return Scan(); } @@ -372,7 +378,7 @@ namespace DTSC { } unsigned int strlen = i[0] * 256 + i[1]; i += 2; - if (indice.size() == strlen && strncmp(indice.data(), i, strlen) == 0){ + if (ind_len == strlen && strncmp(indice, i, strlen) == 0){ return Scan(i+strlen, len-(i-p)); }else{ i = skipDTSC(i+strlen, p+len); @@ -384,6 +390,12 @@ namespace DTSC { return Scan(); } + /// Returns an object representing the named indice of this object. + /// Returns an invalid object if this indice doesn't exist or this isn't an object type. + Scan Scan::getMember(const char * indice){ + return getMember(indice, strlen(indice)); + } + /// Returns an object representing the num-th indice of this array. /// If not an array but an object, it returns the num-th member, instead. /// Returns an invalid object if this indice doesn't exist or this isn't an array or object type.