-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: IR: Fix performance of value-init ranges #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,7 +270,7 @@ newtype TTranslatedElement = | |
not ignoreExpr(initList) and | ||
isFirstValueInitializedElementInRange(initList, elementIndex) and | ||
elementCount = | ||
getNextExplicitlyInitializedElementAfter(initList, elementIndex) - | ||
getEndOfValueInitializedRange(initList, elementIndex) - | ||
elementIndex | ||
} or | ||
// The initialization of a base class from within a constructor. | ||
|
@@ -322,23 +322,30 @@ newtype TTranslatedElement = | |
|
||
/** | ||
* Gets the index of the first explicitly initialized element in `initList` | ||
* whose index is greater than `afterElementIndex`. If there are no remaining | ||
* explicitly initialized elements in `initList`, the result is the total number | ||
* of elements in the array being initialized. | ||
* whose index is greater than `afterElementIndex`, where `afterElementIndex` | ||
* is a first value-initialized element in a value-initialized range in | ||
* `initList`. If there are no remaining explicitly initialized elements in | ||
* `initList`, the result is the total number of elements in the array being | ||
* initialized. | ||
*/ | ||
private int getNextExplicitlyInitializedElementAfter( | ||
ArrayAggregateLiteral initList, int afterElementIndex) { | ||
if exists(int x | | ||
x > afterElementIndex and | ||
exists(initList.getElementExpr(x))) | ||
then ( | ||
if exists(initList.getElementExpr(afterElementIndex + 1)) | ||
then result = afterElementIndex + 1 | ||
else result = getNextExplicitlyInitializedElementAfter(initList, afterElementIndex+1)) | ||
else | ||
result = initList.getType().getUnspecifiedType().(ArrayType).getArraySize() and | ||
// required for binding | ||
initList.isInitialized(afterElementIndex) | ||
private int getEndOfValueInitializedRange(ArrayAggregateLiteral initList, int afterElementIndex) { | ||
result = getNextExplicitlyInitializedElementAfter(initList, afterElementIndex) | ||
or | ||
isFirstValueInitializedElementInRange(initList, afterElementIndex) and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be in both halves of the disjunction? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
not exists(getNextExplicitlyInitializedElementAfter(initList, afterElementIndex)) and | ||
result = initList.getType().getUnspecifiedType().(ArrayType).getArraySize() | ||
} | ||
|
||
/** | ||
* Gets the index of the first explicitly initialized element in `initList` | ||
* whose index is greater than `afterElementIndex`, where `afterElementIndex` | ||
* is a first value-initialized element in a value-initialized range in | ||
* `initList`. | ||
*/ | ||
private int getNextExplicitlyInitializedElementAfter( | ||
ArrayAggregateLiteral initList, int afterElementIndex) { | ||
isFirstValueInitializedElementInRange(initList, afterElementIndex) and | ||
result = min(int i | exists(initList.getElementExpr(i)) and i > afterElementIndex) | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need an
or getNextExplicitlyInitializedElementAfter
too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed.