Index: includes/locale.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/locale.inc,v
retrieving revision 1.256
diff -u -p -r1.256 locale.inc
--- includes/locale.inc	3 Jun 2010 13:57:41 -0000	1.256
+++ includes/locale.inc	12 Jul 2010 07:38:14 -0000
@@ -775,7 +775,11 @@ function _locale_import_one_string($op, 
  *   The string ID of the existing string modified or the new string added.
  */
 function _locale_import_one_string_db(&$report, $langcode, $context, $source, $translation, $textgroup, $location, $mode, $plid = 0, $plural = 0) {
-  $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup", array(':source' => $source, ':context' => $context, ':textgroup' => $textgroup))->fetchField();
+  $hashkey = md5($source . $context);
+  $lid = db_query("SELECT lid FROM {locales_source} WHERE hashkey = :hashkey AND textgroup = :textgroup", array(
+    ':hashkey' => $hashkey,
+    ':textgroup' => $textgroup
+  ))->fetchField();
 
   if (!empty($translation)) {
     // Skip this string unless it passes a check for dangerous code.
@@ -833,6 +837,7 @@ function _locale_import_one_string_db(&$
           'source' => $source,
           'context' => (string) $context,
           'textgroup' => $textgroup,
+          'hashkey' => $hashkey,
         ))
         ->execute();
 
@@ -1199,7 +1204,8 @@ function _locale_parse_js_file($filepath
       // Remove the quotes and string concatenations from the string.
       $string = implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($string, 1, -1)));
 
-      $source = db_query("SELECT lid, location FROM {locales_source} WHERE source = :source AND textgroup = 'default'", array(':source' => $string))->fetchObject();
+      $hashkey = md5($string);
+      $source = db_query("SELECT lid, location FROM {locales_source} WHERE hashkey = :hashkey AND textgroup = 'default'", array(':hashkey' => $hashkey))->fetchObject();
       if ($source) {
         // We already have this source string and now have to add the location
         // to the location column, if this file is not yet present in there.
@@ -1226,6 +1232,7 @@ function _locale_parse_js_file($filepath
             'source' => $string,
             'context' => '',
             'textgroup' => 'default',
+            'hashkey' => $hashkey,
           ))
           ->execute();
       }
Index: modules/locale/locale.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.install,v
retrieving revision 1.61
diff -u -p -r1.61 locale.install
--- modules/locale/locale.install	7 Jul 2010 05:44:03 -0000	1.61
+++ modules/locale/locale.install	12 Jul 2010 07:38:14 -0000
@@ -110,6 +110,24 @@ function locale_update_7002() {
 }
 
 /**
+ * Adds hashkey column to {locales_source}.
+ */
+function locale_update_7003() {
+  $spec = array(
+    'description' => 'MD5 hash of the concatenation of context and string, used for quick lookups.',
+    'type' => 'char',
+    'length' => 32,
+    'not null' => TRUE,
+    'default' => '',
+  );
+  db_add_field('locales_source', 'hashkey', $spec);
+  db_update('locales_source')
+    ->expression('hashkey', 'MD5(source || context)')
+    ->execute();
+  db_add_unique_key('locales_source', 'hashkey', array('hashkey'));
+}
+
+/**
  * @} End of "defgroup updates-6.x-to-7.x"
  */
 
@@ -290,8 +309,18 @@ function locale_schema() {
         'default' => 'none',
         'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
       ),
+      'hashkey' => array(
+        'description' => 'MD5 hash of the concatenation of context and string, used for quick lookups.',
+        'type' => 'char',
+        'length' => 32,
+        'not null' => TRUE,
+        'default' => '',
+      ),
     ),
     'primary key' => array('lid'),
+    'unique keys' => array(
+      'hashkey' => array('hashkey'),
+    ),
     'indexes' => array(
       'source_context' => array(array('source', 30), 'context'),
     ),
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.293
diff -u -p -r1.293 locale.module
--- modules/locale/locale.module	12 May 2010 08:26:14 -0000	1.293
+++ modules/locale/locale.module	12 Jul 2010 07:38:15 -0000
@@ -664,10 +664,10 @@ function locale($string = NULL, $context
   if (!isset($locale_t[$langcode][$context][$string])) {
 
     // We do not have this translation cached, so get it from the DB.
-    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
+    $hashkey = md5($string . (string) $context);
+    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.hashkey = :hashkey AND s.textgroup = 'default'", array(
       ':language' => $langcode,
-      ':source' => $string,
-      ':context' => (string) $context,
+      ':hashkey' => $hashkey,
     ))->fetchObject();
     if ($translation) {
       // We have the source string at least.
@@ -694,6 +694,7 @@ function locale($string = NULL, $context
           'context' => (string) $context,
           'textgroup' => 'default',
           'version' => VERSION,
+          'hashkey' => $hashkey,
         ))
         ->execute();
       $locale_t[$langcode][$context][$string] = TRUE;
