diff --git a/core/includes/gettext.inc b/core/includes/gettext.inc
index 95e84cf..11c1cca 100644
--- a/core/includes/gettext.inc
+++ b/core/includes/gettext.inc
@@ -470,7 +470,10 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL
  *   The string ID of the existing string modified or the new string added.
  */
 function _locale_import_one_string_db(&$report, $langcode, $context, $source, $translation, $location, $mode, $plid = 0, $plural = 0) {
-  $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $source, ':context' => $context))->fetchField();
+  $hashkey = drupal_hash_base64($source . "\0" . $context);
+  $lid = db_query("SELECT lid FROM {locales_source} WHERE hashkey = :hashkey", array(
+    ':hashkey' => $hashkey
+  ))->fetchField();
 
   if (!empty($translation)) {
     // Skip this string unless it passes a check for dangerous code.
@@ -526,6 +529,7 @@ function _locale_import_one_string_db(&$report, $langcode, $context, $source, $t
           'location' => $location,
           'source' => $source,
           'context' => (string) $context,
+          'hashkey' => $hashkey,
         ))
         ->execute();
 
diff --git a/core/includes/locale.inc b/core/includes/locale.inc
index 8a381ed..0425f03 100644
--- a/core/includes/locale.inc
+++ b/core/includes/locale.inc
@@ -635,7 +635,8 @@ function _locale_parse_js_file($filepath) {
     $string =  implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($match['string'], 1, -1)));
     $context = implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($match['context'], 1, -1)));
 
-    $source = db_query("SELECT lid, location FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $string, ':context' => $context))->fetchObject();
+    $hashkey = drupal_hash_base64($string . "\0");
+    $source = db_query("SELECT lid, location FROM {locales_source} WHERE hashkey = :hashkey AND context = :context", array(':hashkey' => $hashkey, ':context' => $context))->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.
@@ -661,6 +662,7 @@ function _locale_parse_js_file($filepath) {
           'location'  => $filepath,
           'source'    => $string,
           'context'   => $context,
+          'hashkey'   => $hashkey,
         ))
         ->execute();
     }
diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install
index a75ee2e..60a7f6c 100644
--- a/core/modules/locale/locale.install
+++ b/core/modules/locale/locale.install
@@ -147,10 +147,18 @@ function locale_schema() {
         'default' => 'none',
         'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
       ),
+      'hashkey' => array(
+        'description' => 'A sha-256 hash of the concatenation of context and string, used for quick lookups.',
+        'type' => 'char',
+        'length' => 44,
+        'not null' => TRUE,
+        'default' => '',
+      ),
     ),
     'primary key' => array('lid'),
     'indexes' => array(
       'source_context' => array(array('source', 30), 'context'),
+      'hashkey' => array('hashkey'),
     ),
   );
 
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 4a786be..fb53562 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -640,10 +640,10 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
   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", array(
+    $hashkey = drupal_hash_base64($string . "\0" . (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", array(
       ':language' => $langcode,
-      ':source' => $string,
-      ':context' => (string) $context,
+      ':hashkey' => $hashkey,
     ))->fetchObject();
     if ($translation) {
       // We have the source string at least.
@@ -669,6 +669,7 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
           'source' => $string,
           'context' => (string) $context,
           'version' => VERSION,
+          'hashkey' => $hashkey,
         ))
         ->execute();
       $locale_t[$langcode][$context][$string] = TRUE;
@@ -791,6 +792,12 @@ function locale_system_update($components) {
 function locale_js_alter(&$javascript) {
   global $language_interface;
 
+  if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
+    // Skip processing for updates because updated code could use updated
+    // database schema probably not compatible with updated processing.
+    return;
+  }
+
   $dir = 'public://' . variable_get('locale_js_directory', 'languages');
   $parsed = variable_get('javascript_parsed', array());
   $files = $new_files = FALSE;
