-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/intl: using a bit more modern c++ memory management features. #19163
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
not always possible (e.g. PHP objects) but when scoped we can manage here to simplify memory managament starting with IntlDateFormat.
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.
+1 on the idea. Some comments.
@@ -70,10 +70,10 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) | |||
size_t locale_len; | |||
bool pattern = false; | |||
UDate date; | |||
TimeZone *timeZone = NULL; | |||
std::unique_ptr<TimeZone> timeZone = NULL; |
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 believe it's not necessary to value-initialize these unique_ptrs.
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.
yes true
"datefmt_format_object") == FAILURE) { | ||
RETURN_FALSE; | ||
} | ||
cal = new GregorianCalendar(Locale::createFromName(locale_str), status); | ||
timeZone = std::unique_ptr<TimeZone>(tz); | ||
cal = std::unique_ptr<Calendar>(new GregorianCalendar(Locale::createFromName(locale_str), status)); |
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.
Can't you use make_unique here instead of unique_ptr+new ?
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 wish but isn't it C++14 minimum ?
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.
Ah right, and it's the ICU version that decides between C++11/C++17... Nvm then ;)
not always possible (e.g. PHP objects) but when scoped we can manage here to simplify memory managament starting with IntlDateFormat.