-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add a filter for religions #13016
base: master
Are you sure you want to change the base?
Add a filter for religions #13016
Conversation
} | ||
|
||
private fun matchesSingleFilter(filter: String, state: StateForConditionals = StateForConditionals.IgnoreConditionals, civ: Civilization? = null): Boolean { | ||
if (filter == "any") return true |
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.
For performance, turn this into a switch with all static cases, and have "else" contain the dynamic cases (name, hasMatchingUnique)
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.
... even if you then duplicate the getFounder() call (because it will nevertheless be called at most once - it will even be called "less" if you get to the else). Don't forget that when(filter) { name -> true
... works1, and afterwards it may be simple enough to warrant fun(): T { return x }
=> fun() = x
, which often reads better2. Though I admit both hints do have negative precedents in our code - all the matchesSingleFilter
I see don't follow them.
Also - aren't the two last if
lines absolutely identical?
Footnotes
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.
nevertheless be called at most once - it will even be called "less" if you get to the else). Don't forget that
when(filter) { name -> true
... works
Java is one such language where switch statements requires a compile-time here if I understand correctly. So that also would compile to an if chain if I understand correctly rather than an actual jvm switch
Also - aren't the two last
if
lines absolutely identical?
Goddammit
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.
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.
context
Wow. Not really surprising given what 7th just said about Java, but a bit disappointing the compiler won't resolve that itself...
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.
Makes me associate - what was up with interning for Strings in Kotlin? If all strings involved here were interned and coalesced, it wouldn't even need a call to equals(), comparing GC id's or pointers or whatever would be enough, and for the constants part it could precompile a vtable-type thingy. Someone must have determined that all the extra indexing work upsert's overshadows select performance...
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.
In all JVM languages, interning is not default behavior because it's essentially a hashmap getOrPut which is not cheap
I did consider doing it for RAM purposes but didn't see it made a difference
Actually, question: should this accept a civFilter as well? E.g. |
I think we can forgo that for now, if no one is asking for it it sounds kind of 'out there' |
And you get a filter, and you get a filter. Everything gets a multifilter
I mostly thought of this to allow for moving uniques for unlocking religious buildings off of the beliefs themselves and onto the buildings, but almost surely some other modder will find use for it
I really, really, really, really want to find some way to integrate this into city filter (as I believe there is actually a niche case use for that), but I can't figure out how I would go about doing that or if it's just the unique in question needs better alternatives