diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml
index f6442f7..371f06d 100644
--- a/core/config/schema/core.entity.schema.yml
+++ b/core/config/schema/core.entity.schema.yml
@@ -69,6 +69,7 @@ core.entity_view_display.*.*.*:
     content:
       type: sequence
       label: 'Field formatters'
+      orderby: key
       sequence:
         - type: mapping
           label: 'Field formatter'
diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php
index 51ade6c..b39c64c 100644
--- a/core/lib/Drupal/Core/Config/Config.php
+++ b/core/lib/Drupal/Core/Config/Config.php
@@ -212,8 +212,8 @@ public function save() {
     if ($this->typedConfigManager->hasConfigSchema($this->name)) {
       // Ensure that the schema wrapper has the latest data.
       $this->schemaWrapper = NULL;
-      foreach ($this->data as $key => $value) {
-        $this->data[$key] = $this->castValue($key, $value);
+      foreach (array_keys($this->data) as $key) {
+        $this->data[$key] = $this->castValue($key);
       }
     }
     else {
diff --git a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php
index 8becdd7..63f0af7 100644
--- a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php
+++ b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php
@@ -6,6 +6,7 @@
  */
 
 namespace Drupal\Core\Config\Schema;
+use Drupal\Core\TypedData\PrimitiveInterface;
 use Drupal\Core\TypedData\TraversableTypedDataInterface;
 
 /**
@@ -109,4 +110,20 @@ public function getIterator() {
     return new \ArrayIterator($this->getElements());
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getCastedValue() {
+    $value = array();
+    foreach ($this->getElements() as $key => $element) {
+      if ($element instanceof PrimitiveInterface) {
+        $value[$key] = $element->getValue();
+      }
+      else {
+        $value[$key] = method_exists($element, 'getCastedValue') ? $element->getCastedValue() : $element->getValue();
+      }
+    }
+    return $value;
+  }
+
 }
diff --git a/core/lib/Drupal/Core/Config/Schema/Sequence.php b/core/lib/Drupal/Core/Config/Schema/Sequence.php
index bce81a9..a0da0c0 100644
--- a/core/lib/Drupal/Core/Config/Schema/Sequence.php
+++ b/core/lib/Drupal/Core/Config/Schema/Sequence.php
@@ -8,6 +8,7 @@
 namespace Drupal\Core\Config\Schema;
 
 use Drupal\Core\TypedData\ListInterface;
+use Drupal\Core\TypedData\TypedDataInterface;
 
 /**
  * Defines a configuration element of type Sequence.
@@ -21,6 +22,15 @@ class Sequence extends ArrayElement implements ListInterface {
    */
   protected $itemDefinition;
 
+  public function __construct($definition,  $name = NULL, TypedDataInterface $parent = NULL) {
+    parent::__construct($definition, $name, $parent);
+
+    if (!isset($this->definition['orderby'])) {
+      $this->definition['orderby'] = 'none';
+    }
+  }
+
+
   /**
    * {@inheritdoc}
    */
@@ -35,6 +45,20 @@ protected function parse() {
       $data_definition =  $this->buildDataDefinition($definition, $value, $key);
       $elements[$key] = $this->parseElement($key, $value, $data_definition);
     }
+
+    if (isset($data_definition) && $this->definition['orderby'] == 'value' && is_subclass_of($data_definition->getClass(), '\Drupal\Core\TypedData\PrimitiveInterface')) {
+      usort($elements, function ($a, $b) {
+        if ($a->getValue() == $b->getValue()) {
+            return 0;
+        }
+        return ($a->getValue() < $b->getValue()) ? -1 : 1;
+      });
+    }
+
+    if ($this->definition['orderby'] == 'key') {
+      ksort($elements);
+    }
+
     return $elements;
   }
 
diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php
index 4af470e..6010d13 100644
--- a/core/lib/Drupal/Core/Config/StorableConfigBase.php
+++ b/core/lib/Drupal/Core/Config/StorableConfigBase.php
@@ -8,6 +8,7 @@
 namespace Drupal\Core\Config;
 
 use Drupal\Component\Utility\String;
+use Drupal\Core\Config\Schema\ArrayElement;
 use Drupal\Core\Config\Schema\Ignore;
 use Drupal\Core\TypedData\PrimitiveInterface;
 use Drupal\Core\TypedData\Type\FloatInterface;
@@ -168,8 +169,6 @@ protected function validateValue($key, $value) {
    *
    * @param string $key
    *   A string that maps to a key within the configuration data.
-   * @param string $value
-   *   Value to associate with the key.
    *
    * @return mixed
    *   The value cast to the type indicated in the schema.
@@ -177,8 +176,9 @@ protected function validateValue($key, $value) {
    * @throws \Drupal\Core\Config\UnsupportedDataTypeConfigException
    *   If the value is unsupported in configuration.
    */
-  protected function castValue($key, $value) {
+  protected function castValue($key) {
     $element = $this->getSchemaWrapper()->get($key);
+    $value = $element->getValue();
     // Do not cast value if it is unknown or defined to be ignored.
     if ($element && ($element instanceof Undefined || $element instanceof Ignore)) {
       // Do validate the value (may throw UnsupportedDataTypeConfigException)
@@ -186,24 +186,10 @@ protected function castValue($key, $value) {
       $this->validateValue($key, $value);
       return $value;
     }
-    if (is_scalar($value) || $value === NULL) {
-      if ($element && $element instanceof PrimitiveInterface) {
-        // Special handling for integers and floats since the configuration
-        // system is primarily concerned with saving values from the Form API
-        // we have to special case the meaning of an empty string for numeric
-        // types. In PHP this would be casted to a 0 but for the purposes of
-        // configuration we need to treat this as a NULL.
-        $empty_value =  $value === '' && ($element instanceof IntegerInterface || $element instanceof FloatInterface);
-
-        if ($value === NULL || $empty_value) {
-          $value = NULL;
-        }
-        else {
-          $value = $element->getCastedValue();
-        }
-      }
+    if ($element instanceof PrimitiveInterface) {
+      $value = $element->getValue();
     }
-    else {
+    elseif ($element instanceof ArrayElement) {
       // Throw exception on any non-scalar or non-array value.
       if (!is_array($value)) {
         throw new UnsupportedDataTypeConfigException(String::format('Invalid data type for config element @name:@key', array(
@@ -211,10 +197,7 @@ protected function castValue($key, $value) {
           '@key' => $key,
         )));
       }
-      // Recurse into any nested keys.
-      foreach ($value as $nested_value_key => $nested_value) {
-        $value[$nested_value_key] = $this->castValue($key . '.' . $nested_value_key, $nested_value);
-      }
+      $value = $element->getCastedValue();
     }
     return $value;
   }
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Boolean.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Boolean.php
index 874fcbb..86e8c81 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Boolean.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Boolean.php
@@ -26,6 +26,13 @@ class Boolean extends PrimitiveBase implements BooleanInterface {
   /**
    * {@inheritdoc}
    */
+  public function getValue() {
+    return (bool) $this->value;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function getCastedValue() {
     return (bool) $this->value;
   }
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Float.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Float.php
index 3980f0a..5cdb727 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Float.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Float.php
@@ -23,10 +23,19 @@
  */
 class Float extends PrimitiveBase implements FloatInterface {
 
+  public function getValue() {
+    if ($this->value === NULL || $this->value === '') {
+      return NULL;
+    }
+
+    return (float) $this->value;
+  }
+
   /**
    * {@inheritdoc}
    */
   public function getCastedValue() {
     return (float) $this->value;
   }
+
 }
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Integer.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Integer.php
index b5fe36a..0ddc921 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Integer.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Integer.php
@@ -26,6 +26,17 @@ class Integer extends PrimitiveBase implements IntegerInterface {
   /**
    * {@inheritdoc}
    */
+  public function getValue() {
+    if ($this->value === NULL || $this->value === '') {
+      return NULL;
+    }
+
+    return (int) $this->value;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function getCastedValue() {
     return (int) $this->value;
   }
diff --git a/core/modules/config/src/Tests/SchemaConfigListenerTest.php b/core/modules/config/src/Tests/SchemaConfigListenerTest.php
index bac6245..682dbfc 100644
--- a/core/modules/config/src/Tests/SchemaConfigListenerTest.php
+++ b/core/modules/config/src/Tests/SchemaConfigListenerTest.php
@@ -32,10 +32,10 @@ public function testConfigSchemaChecker() {
     try {
       $this->config('config_schema_test.schemaless')->set('foo', 'bar')->save();
       $this->fail($message);
-    }
-    catch (SchemaIncompleteException $e) {
+    } catch (SchemaIncompleteException $e) {
       $this->pass($message);
-      $this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage());
+      $this->assertEqual('No schema for config_schema_test.schemaless',
+        $e->getMessage());
     }
 
     // Test a valid schema.
@@ -44,8 +44,7 @@ public function testConfigSchemaChecker() {
     try {
       $config->save();
       $this->pass($message);
-    }
-    catch (SchemaIncompleteException $e) {
+    } catch (SchemaIncompleteException $e) {
       $this->fail($message);
     }
 
@@ -57,10 +56,10 @@ public function testConfigSchemaChecker() {
     try {
       $config->save();
       $this->fail($message);
-    }
-    catch (SchemaIncompleteException $e) {
+    } catch (SchemaIncompleteException $e) {
       $this->pass($message);
-      $this->assertEqual('Schema errors for config_test.types with the following errors: config_test.types:foo missing schema, config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence', $e->getMessage());
+      $this->assertEqual('Schema errors for config_test.types with the following errors: config_test.types:foo missing schema, config_test.types:array variable type is integer but applied schema class is Drupal\Core\Config\Schema\Sequence',
+        $e->getMessage());
     }
   }
 
diff --git a/core/modules/user/src/Plugin/views/field/Permissions.php b/core/modules/user/src/Plugin/views/field/Permissions.php
index bec1689..c479bac 100644
--- a/core/modules/user/src/Plugin/views/field/Permissions.php
+++ b/core/modules/user/src/Plugin/views/field/Permissions.php
@@ -38,6 +38,11 @@ class Permissions extends PrerenderList {
   protected $moduleHandler;
 
   /**
+   * @var \Drupal\user\RoleInterface[]
+   */
+  protected $roles;
+
+  /**
    * Constructs a Drupal\Component\Plugin\PluginBase object.
    *
    * @param array $configuration
@@ -79,42 +84,39 @@ public function query() {
     $this->field_alias = $this->aliases['uid'];
   }
 
+  public function getRoles() {
+    if (!isset($this->roles)) {
+      $this->roles = $this->roleStorage->loadMultiple();
+    }
+
+    return $this->roles;
+  }
+
   public function preRender(&$values) {
-    $uids = array();
+    $roles = $this->getRoles();
     $this->items = array();
-
     $permission_names = \Drupal::service('user.permissions')->getPermissions();
 
-    $rids = array();
     foreach ($values as $result) {
-      $user_rids = $this->getEntity($result)->getRoles();
+      /**
+       * @var \Drupal\user\UserInterface $account
+       */
+      $account = $this->getEntity($result);
       $uid = $this->getValue($result);
+      $this->items[$uid] = array();
 
-      foreach ($user_rids as $rid) {
-        $rids[$rid][] = $uid;
+      foreach ($account->getRoles() as $rid) {
+        $this->items[$uid] += array_intersect_key($permission_names, array_flip($roles[$rid]->getPermissions()));
       }
     }
 
-    if ($rids) {
-      $roles = $this->roleStorage->loadMultiple(array_keys($rids));
-      foreach ($rids as $rid => $role_uids) {
-        foreach ($roles[$rid]->getPermissions() as $permission) {
-          foreach ($role_uids as $uid) {
-            $this->items[$uid][$permission]['permission'] = $permission_names[$permission]['title'];
-          }
-        }
-      }
-
-      foreach ($uids as $uid) {
-        if (isset($this->items[$uid])) {
-          ksort($this->items[$uid]);
-        }
-      }
+    foreach ($this->items as &$permissions) {
+      $permissions = array_intersect_key($permission_names, $permissions);
     }
   }
 
   function render_item($count, $item) {
-    return $item['permission'];
+    return $item['title'];
   }
 
   /*
