-
Notifications
You must be signed in to change notification settings - Fork 28
Get rid of empty init functions #701
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
Conversation
Doesn't allocate handles
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.
Would it not be easier to improve the generation of the bridge-functions instead of trying to find and optimize them after the fact?
initFuncs.forEach(func -> { | ||
ImVar globalBridge = null; | ||
for (ImVar global : prog.getGlobals()) { | ||
if (global.getName().equals("ref_function_" + func.getName())) { |
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.
I don't like using the name here. Names should not matter in the intermediate language.
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.
What to use then?
List<ImFunction> initFuncs = prog.getFunctions().stream().filter(func -> func.getName().startsWith | ||
("init_") && func.getBody().size() == 1).collect(Collectors.toList()); | ||
|
||
initFuncs.forEach(func -> { |
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.
please use normal for-loops -- better performance, better stack traces, better debugging, easier to read
if (body.get(finalI - 1) instanceof ImFunctionCall) { | ||
body.get(finalI - 1).replaceBy(JassIm.ImNull()); | ||
} | ||
body.get(finalI + 1).replaceBy(JassIm.ImNull()); |
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.
What is the -1 and +1 doing here? Looks like you are assuming that there are always certain other statements around a call to TriggerAddCondition
but that does not seem very reliable to me.
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.
The init calls are always generated the same way. Unless someone names a function "ref_function_" or so (which is the name issue above) then it seems reliable to me.
No idea where to start with that tbh. The old ticket & solution have been around for a while, this is one without inlining again. |
@peq ? |
Removes empty package init functions, see #511