Closed Bug 659820 Opened 13 years ago Closed 13 years ago

Replace nsContentUtils::GetCharPref() and nsContentUtils::GetStringPref() with Preferences::GetCString() and Preferences::GetString()

Categories

(Core :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla7

People

(Reporter: masayuki, Assigned: masayuki)

References

Details

Attachments

(4 files, 7 obsolete files)

(deleted), patch
Details | Diff | Splinter Review
(deleted), patch
Details | Diff | Splinter Review
(deleted), patch
Details | Diff | Splinter Review
(deleted), patch
roc
: review+
Details | Diff | Splinter Review
Attached patch Part.2 Replace (obsolete) (deleted) — Splinter Review
Attachment #535231 - Flags: review?(roc)
Attachment #535230 - Flags: review? → review?(roc)
Comment on attachment 535230 [details] [diff] [review] Part.1 Change the string params of Preferences class from ns*String to nsA*String Review of attachment 535230 [details] [diff] [review]: -----------------------------------------------------------------
Attachment #535230 - Flags: review?(roc) → review+
Hmm. Actually, can we have these methods (and those in bug 659821) return a string as a direct result, the way the nsContentUtils methods do?
GetChar() and GetLocalizedChar() are for nsCString. GetString() and GetLocalizedString() are for nsString. nsAdopting*String steals the buffer of original class. So, they are better for the return value.
Attachment #535231 - Attachment is obsolete: true
Attachment #535231 - Flags: review?(roc)
Attachment #535307 - Flags: review?(roc)
Attached patch Part.3 Replace (obsolete) (deleted) — Splinter Review
Attachment #535308 - Flags: review?(roc)
Sorry, I posted old patch.
Attachment #535307 - Attachment is obsolete: true
Attachment #535307 - Flags: review?(roc)
Attachment #535310 - Flags: review?(roc)
Comment on attachment 535310 [details] [diff] [review] Part.2 Re-implement Preferences::Get(Char|LocalizedString)() Review of attachment 535310 [details] [diff] [review]: ----------------------------------------------------------------- I think the GetChar versions should be GetCString.
Comment on attachment 535538 [details] [diff] [review] Part.2 Reimplement Preferences::(G|S)et(Char|LoclizedString)() to Preferences::(G|S)et(Localized)CString() Review of attachment 535538 [details] [diff] [review]: -----------------------------------------------------------------
Attachment #535538 - Flags: review?(roc) → review+
Moved from bug 659821 for clearing order of the patches.
Attachment #535308 - Attachment is obsolete: true
Attachment #535540 - Attachment is obsolete: true
Attachment #535308 - Flags: review?(roc)
Attached patch Part.4 Do replace (deleted) — Splinter Review
Attachment #535548 - Flags: review?(roc)
Comment on attachment 535548 [details] [diff] [review] Part.4 Do replace Review of attachment 535548 [details] [diff] [review]: -----------------------------------------------------------------
Attachment #535548 - Flags: review?(roc) → review+
Summary: Replace nsContentUtils::GetCharPref() and nsContentUtils::GetStringPref() with Preferences::GetChar() → Replace nsContentUtils::GetCharPref() and nsContentUtils::GetStringPref() with Preferences::GetCString() and Preferences::GetString()
Is there a reason the GetString() functions take a string pointer instead of a writable string reference like all other string getters in our code?
This approach makes for shorter caller code.
Why? Passing |str| and passing |&str| should be the same speed....
I meant the same length...
GetBool() and GetInt() have two style methods: static PRBool GetBool(const char* aPref, PRBool aDefault = PR_FALSE); static PRInt32 GetInt(const char* aPref, PRInt32 aDefault = 0); and static nsresult GetBool(const char* aPref, PRBool* aResult); static nsresult GetInt(const char* aPref, PRInt32* aResult); For overloading, the aResult must be pointer. On the other hand, string related methods have following two styles: static nsAdoptingCString GetCString(const char* aPref); static nsAdoptingString GetString(const char* aPref); and static nsresult GetCString(const char* aPref, nsACString* aResult); static nsresult GetString(const char* aPref, nsAString* aResult); So, string related methods don't have aDefault. However, if we change aResult from pointer to reference, doesn't that make API users confused?
This particular user was confused by the current API... the pointer version is the standard out param variant for ints and bools throughout the codebase, bug XPCOM string out params are references...
(In reply to comment #21) > static nsresult GetCString(const char* aPref, nsACString* aResult); > static nsresult GetString(const char* aPref, nsAString* aResult); Hmm, Boris, are you saying that these should be references instead of pointers?
The second argument for both of those, yes.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: