Skip to content

Commit

Permalink
Avoid double lookup in opIndex for std.json.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrejMitrovic committed May 23, 2014
1 parent 8d5686a commit 7ac188b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions std/json.d
Expand Up @@ -337,9 +337,10 @@ struct JSONValue
/// Throws $(D JSONException) if $(D type) is not $(D JSON_TYPE.OBJECT).
ref inout(JSONValue) opIndex(string k) inout
{
enforceEx!JSONException(k in this,
"Key not found: " ~ k);
return store.object[k];
enforceEx!JSONException(type == JSON_TYPE.OBJECT,
"JSONValue is not an object");
return *enforceEx!JSONException(k in store.object,
"Key not found: " ~ k);
}

auto opBinaryRight(string op : "in")(string k) const
Expand Down

0 comments on commit 7ac188b

Please sign in to comment.