From 5df582dd3229789364ae3fa75575fd978ca3282d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 4 Dec 2019 12:38:38 -0500 Subject: Feature/string hash review (#1142) * * Added ConstArrayView * Made StringSlicePool have styles * Remove point about strings not having terminating 0 (they do), and restriction around "" * spCalcStringHash -> spComputeStringHash * Small code improvements. Closer to coding conventions. * Fix small bug with Empty adding c string. * Fix typo in assert. * Fix ArrayView compiling issue on gcc/clang. * Remove tabs. * Improve comments around StringSlicePool. Simplify getting the added slices. --- source/slang/slang-ir-string-hash.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'source/slang/slang-ir-string-hash.cpp') diff --git a/source/slang/slang-ir-string-hash.cpp b/source/slang/slang-ir-string-hash.cpp index b9e2d4045..0a15ba52d 100644 --- a/source/slang/slang-ir-string-hash.cpp +++ b/source/slang/slang-ir-string-hash.cpp @@ -47,7 +47,7 @@ void replaceGetStringHash(IRModule* module, SharedIRBuilder& sharedBuilder, Stri void replaceGetStringHashWithGlobal(IRModule* module, SharedIRBuilder& sharedBuilder) { - StringSlicePool pool; + StringSlicePool pool(StringSlicePool::Style::Empty); replaceGetStringHash(module, sharedBuilder, pool); addGlobalHashedStringLiterals(pool, sharedBuilder); } @@ -56,7 +56,7 @@ void findGlobalHashedStringLiterals(IRModule* module, StringSlicePool& pool) { IRModuleInst* moduleInst = module->getModuleInst(); - for (IRInst* child = moduleInst->getFirstDecorationOrChild(); child; child = child->getNextInst()) + for(IRInst* child : moduleInst->getChildren()) { if (IRGlobalHashedStringLiterals* hashedStringLits = as(child)) { @@ -72,7 +72,8 @@ void findGlobalHashedStringLiterals(IRModule* module, StringSlicePool& pool) void addGlobalHashedStringLiterals(const StringSlicePool& pool, SharedIRBuilder& sharedBuilder) { - if (pool.getNumSlices() <= StringSlicePool::kNumDefaultHandles) + auto slices = pool.getAdded(); + if (slices.getCount() == 0) { return; } @@ -86,18 +87,16 @@ void addGlobalHashedStringLiterals(const StringSlicePool& pool, SharedIRBuilder& // We need to add a global instruction that references all of these string literals builder.setInsertInto(module->getModuleInst()); - Index numSlices = Index(pool.getNumSlices() - StringSlicePool::kNumDefaultHandles); + const Index slicesCount = slices.getCount(); - IRInst* globalHashedInst = createEmptyInst(module, kIROp_GlobalHashedStringLiterals, int(numSlices)); + IRInst* globalHashedInst = createEmptyInst(module, kIROp_GlobalHashedStringLiterals, int(slicesCount)); builder.addInst(globalHashedInst); auto operands = globalHashedInst->getOperands(); - for (Index i = 0; i < numSlices; ++i) + for (Index i = 0; i < slicesCount; ++i) { - UnownedStringSlice slice = pool.getSlice(StringSlicePool::Handle(i + StringSlicePool::kNumDefaultHandles)); - IRStringLit* stringLit = builder.getStringValue(slice); - + IRStringLit* stringLit = builder.getStringValue(slices[i]); operands[i].init(globalHashedInst, stringLit); } -- cgit v1.2.3