Bug 97860 - Make functions in Localizer class "const"
Summary: Make functions in Localizer class "const"
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-27 21:57 PDT by yosin
Modified: 2012-09-30 23:11 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yosin 2012-09-27 21:57:52 PDT
Following functions in class Localizer[1] should have "const" specifier to use constant reference to Localizer object for code readability and allow optimization by compiler.

 - convertToLocalizedNumber()
 - convertFromLocalizedNumber()
 - localizedDecimalSeparator()
 - timeFormat()
 - shortTimeFormat()
 - timeAMPMLabels()

Once we can use constant reference Localizer object, we should change use sites to use constant reference, please file another bug:
 - Localizer& Documenet::getLocalizer()
 - BaseMultipleFieldsDateAndTimeInputType::updateInnerTextValue()
    Localizer& localizer = element()->document()->getLocalizer(element()->computeInheritedLanguage());
 - DateTimeEditBuilder member variable
    Localizer& m_localize
 - DateTimeEditElement::LayoutParameters
    LayoutParameters(Localizer& localizer, const StepRange& stepRange)
    Localizer& localizer
 - Maybe more

= References =
[1] http://trac.webkit.org/browser/trunk/Source/WebCore/platform/text/Localizer.h
Comment 1 Alexey Proskuryakov 2012-09-28 09:59:40 PDT
I'm not convinced that this is a worthwhile thing to do. Const is not really useful for optimization, because the qualifier can be dropped with const_cast at any time, and compiler must expect that. And extra visual noise does not improve readability.

Const is useful to statically ensure correctness, which is not an issue for immutable objects like Localizer class instances. 

There are additional considerations why we don't use const in other cases (e.g. why we don't use "const Node&"), which are out of scope to discuss here.
Comment 2 yosin 2012-09-30 23:11:21 PDT
Making Localizer "const" may reduce below comments during review.
Also for me, adding "const" improves readability.

From review for https://bugs.webkit.org/show_bug.cgi?id=97318
View in context: https://bugs.webkit.org/attachment.cgi?id=165971&action=review

> Source/WebCore/html/shadow/DateTimeNumericFieldElement.h:75
> +    Localizer& localizer() const;

Can the return value be const?