diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-03-10 14:41:42 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-05-04 14:01:25 +0200 |
commit | 757f50166b5186a1fcfb5e7e5737801f094fda1b (patch) | |
tree | b8e9beadd55f72e46a76b58b5a5331562d0f4c54 | |
parent | 743368d27fdd4139451bf93f6141ebaf542387f1 (diff) | |
download | qtdeclarative-757f50166b5186a1fcfb5e7e5737801f094fda1b.tar.gz |
Runtime codegen: Avoid memset for zeroing
We can just use calloc and zero-initialization.
Change-Id: I88dc79d5b880253655159ae3b4385b9792a18ec6
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4executablecompilationunit.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp index a39def16bb..a73d5031ec 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit.cpp +++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp @@ -112,17 +112,14 @@ QV4::Function *ExecutableCompilationUnit::linkToEngine(ExecutionEngine *engine) Q_ASSERT(!runtimeStrings); Q_ASSERT(data); const quint32 stringCount = totalStringCount(); - runtimeStrings = (QV4::Heap::String **)malloc(stringCount * sizeof(QV4::Heap::String*)); - // memset the strings to 0 in case a GC run happens while we're within the loop below - memset(runtimeStrings, 0, stringCount * sizeof(QV4::Heap::String*)); + // strings need to be 0 in case a GC run happens while we're within the loop below + runtimeStrings = (QV4::Heap::String **)calloc(stringCount, sizeof(QV4::Heap::String*)); for (uint i = 0; i < stringCount; ++i) runtimeStrings[i] = engine->newString(stringAt(i)); + // zero-initialize regexps in case a GC run happens while we're within the loop below runtimeRegularExpressions - = new QV4::Value[data->regexpTableSize]; - // memset the regexps to 0 in case a GC run happens while we're within the loop below - memset(runtimeRegularExpressions, 0, - data->regexpTableSize * sizeof(QV4::Value)); + = new QV4::Value[data->regexpTableSize] {}; for (uint i = 0; i < data->regexpTableSize; ++i) { const CompiledData::RegExp *re = data->regexpAt(i); uint f = re->flags(); @@ -154,12 +151,11 @@ QV4::Function *ExecutableCompilationUnit::linkToEngine(ExecutionEngine *engine) } if (data->jsClassTableSize) { + // zero the regexps with calloc in case a GC run happens while we're within the loop below runtimeClasses - = (QV4::Heap::InternalClass **)malloc(data->jsClassTableSize - * sizeof(QV4::Heap::InternalClass *)); - // memset the regexps to 0 in case a GC run happens while we're within the loop below - memset(runtimeClasses, 0, - data->jsClassTableSize * sizeof(QV4::Heap::InternalClass *)); + = (QV4::Heap::InternalClass **)calloc(data->jsClassTableSize, + sizeof(QV4::Heap::InternalClass *)); + for (uint i = 0; i < data->jsClassTableSize; ++i) { int memberCount = 0; const CompiledData::JSClassMember *member |