diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-12-04 12:38:38 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-04 12:38:38 -0500 |
| commit | 5df582dd3229789364ae3fa75575fd978ca3282d (patch) | |
| tree | 89f66f7c2427030b0e9a0ed0754fc380a5f4b21c /source/slang/slang-ir-string-hash.cpp | |
| parent | 9653dcc2c9d5d20d3d0e8918aaf1d5b09e963060 (diff) | |
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.
Diffstat (limited to 'source/slang/slang-ir-string-hash.cpp')
| -rw-r--r-- | source/slang/slang-ir-string-hash.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
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<IRGlobalHashedStringLiterals>(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); } |
