From 2f7855d6ccc3c12b7eb3317ae2b9e93fb98bac7c Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 25 Feb 2021 14:02:10 +0000 Subject: [PATCH] Optimise converting rich resource text to text only * We don't have to do the full text document cache to just append the strings. --- qrenderdoc/Code/QRDUtils.cpp | 43 ++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 9af6c70fd..288d704b1 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -201,6 +201,7 @@ struct RichResourceText // a plain-text version of the document, suitable for e.g. copy-paste QString text; + int textCacheId = 0; // the ideal width for the document int idealWidth = 0; @@ -209,6 +210,43 @@ struct RichResourceText // cache the context once we've obtained it. ICaptureContext *ctxptr = NULL; + void cacheText(const QWidget *widget) + { + if(!ctxptr) + ctxptr = getCaptureContext(widget); + + if(!ctxptr) + return; + + ICaptureContext &ctx = *(ICaptureContext *)ctxptr; + + int refCache = ctx.ResourceNameCacheID(); + + if(textCacheId == refCache) + return; + + textCacheId = refCache; + + text.clear(); + + for(const QVariant &v : fragments) + { + if(v.userType() == qMetaTypeId()) + { + QString resname = GetTruncatedResourceName(ctx, v.value()); + text += resname; + } + else if(v.type() == QVariant::UInt) + { + text += lit("EID @%1").arg(v.toUInt()); + } + else + { + text += v.toString(); + } + } + } + void cacheDocument(const QWidget *widget) { if(!ctxptr) @@ -221,10 +259,11 @@ struct RichResourceText int refCache = ctx.ResourceNameCacheID(); - if(cacheId == refCache) + if(cacheId == refCache && textCacheId == refCache) return; cacheId = refCache; + textCacheId = refCache; // use a table to ensure images don't screw up the baseline for text. DON'T JUDGE ME. QString html = lit(""); @@ -389,7 +428,7 @@ ICaptureContext *getCaptureContext(const QWidget *widget) QString ResIdTextToString(RichResourceTextPtr ptr) { - ptr->cacheDocument(NULL); + ptr->cacheText(NULL); return ptr->text; }