-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
ICU-22994 Use C++ typeid() instead of Calendar::getType() for calendar type comparison #3310
ICU-22994 Use C++ typeid() instead of Calendar::getType() for calendar type comparison #3310
Conversation
2fb4782
to
53bbf05
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
53bbf05
to
8f48ddf
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
8f48ddf
to
f7cbd62
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
icu4c/source/i18n/datefmt.cpp
Outdated
// Avoid a heap allocation and corresponding free for the common case | ||
if (uprv_strcmp(calType, "gregorian") == 0) { | ||
if (GregorianCalendar::getStaticClassID() == fCalendar->getDynamicClassID()) { |
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.
Questions that I had asked on the ticket:
- Why is using getType() bad? It seems like it’s public and advertised.
- Is strcmp() actually slow for short strings that usually differ in the first couple of characters?
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 think such usage is bad because our code could easily misspell the string
nit: commit message typo "misuage"; i just fixed the PR title |
PTAL |
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.
This all looks fine. No notes beyond those the other reviewers have already put out.
That said, it looks like all of this is calendar-specific logic in the date formatters-- that is, lots of "if this is an XXX calendar, do this special thing we only do for XXX calendars". It's clearly been that way for a long time, and I'm certainly not proposing you redesign the whole thing now, but I wonder (longer term) if we can find a way to eliminate all of that in favor of better compartmentalization between classes and more actual polymorphic behavior. I don't know what that'd look like or if it's really worth the trouble, but it really seems like the formatters have to know way too much about the internals of the calendars right now.
I totally agree with you. It is my desire to do that later but I still have trouble to figure out how to achieve that. |
Yeah, it's anything but straightforward. We'll figure something out eventually, I'm sure. |
one issue filed under https://unicode-org.atlassian.net/browse/ICU-23030 |
dc9937d
ftang made the changes that roubert requested
I dismissed @roubert 's request for changes since @FrankYFTang made all of those changes. Please squash, and watch for commit message typos. |
…r type comparison See unicode-org#3310
dc9937d
to
ce491fb
Compare
Hooray! The files in the branch are the same across the force-push. 😃 ~ Your Friendly Jira-GitHub PR Checker Bot |
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.
LGTM
Use typeid for calendar type comparison instead of strcmp.
Checklist