at the top of the startup profiles. now, no longer escape/allocate strings
if that's not needed
pmo-trunk-r2913
-modest_account_mgr_account_exists (ModestAccountMgr * self, const gchar * name,
+modest_account_mgr_account_exists (ModestAccountMgr * self, const gchar* name,
gboolean server_account)
{
ModestAccountMgrPrivate *priv;
gboolean server_account)
{
ModestAccountMgrPrivate *priv;
gboolean retval;
GError *err = NULL;
gboolean retval;
GError *err = NULL;
- g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE);
+ g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (name, FALSE);
keyname = _modest_account_mgr_get_account_keyname (name, NULL, server_account);
g_return_val_if_fail (name, FALSE);
keyname = _modest_account_mgr_get_account_keyname (name, NULL, server_account);
+
+/* optimization: only with non-alphanum chars, escaping is needed */
+inline static gboolean
+is_alphanum (const gchar* str)
+{
+ const gchar *cursor;
+ for (cursor = str; cursor && *cursor; ++cursor) {
+ const char c = *cursor;
+ /* we cannot trust isalnum(3), because it might consider locales */
+ /* numbers ALPHA alpha */
+ if (!((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122)))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
/* must be freed by caller */
gchar *
_modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account)
{
/* must be freed by caller */
gchar *
_modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar * name, gboolean server_account)
{
- gchar *retval = NULL;
-
gchar *namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
gchar *namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
+ gchar *escaped_account_name, *escaped_name;
if (!account_name)
return g_strdup (namespace);
if (!account_name)
return g_strdup (namespace);
- /* Always escape the conf keys, so that it is acceptable to gconf: */
- gchar *escaped_account_name = account_name ? modest_conf_key_escape (account_name) : NULL;
- gchar *escaped_name = name ? modest_conf_key_escape (name) : NULL;
+ /* optimization: only escape names when need to be escaped */
+ if (is_alphanum (account_name))
+ escaped_account_name = (gchar*)account_name;
+ else
+ escaped_account_name = modest_conf_key_escape (account_name);
+
+ if (is_alphanum (name))
+ escaped_name = (gchar*)name;
+ else
+ escaped_name = modest_conf_key_escape (name);
+ //////////////////////////////////////////////////////////////
if (escaped_account_name && escaped_name)
retval = g_strconcat (namespace, "/", escaped_account_name, "/", escaped_name, NULL);
if (escaped_account_name && escaped_name)
retval = g_strconcat (namespace, "/", escaped_account_name, "/", escaped_name, NULL);
- g_free (escaped_name);
- g_free (escaped_account_name);
-
+ /* g_free is only needed if we actually allocated anything */
+ if (name != escaped_name)
+ g_free (escaped_name);
+ if (account_name != escaped_account_name)
+ g_free (escaped_account_name);
+
void
modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name,
void
modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name,
{
ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
if (busy)
{
ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
if (busy)