You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Adam Kocoloski <ko...@apache.org> on 2010/07/12 18:44:06 UTC
Re: svn commit: r963042 - /couchdb/trunk/src/couchdb/couch_util.erl
Hi Filipe, I thought about doing this once, but lists:keystore/4 only drops the first occurrence of K, whereas json_apply_field drops all matching occurrences. Do we care about the case where multiple values for e.g. the Vary header have been supplied by the user in a show function?
Adam
On Jul 11, 2010, at 6:31 AM, fdmanana@apache.org wrote:
> Author: fdmanana
> Date: Sun Jul 11 10:31:38 2010
> New Revision: 963042
>
> URL: http://svn.apache.org/viewvc?rev=963042&view=rev
> Log:
> Removing unnecessary code.
>
> Modified:
> couchdb/trunk/src/couchdb/couch_util.erl
>
> Modified: couchdb/trunk/src/couchdb/couch_util.erl
> URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_util.erl?rev=963042&r1=963041&r2=963042&view=diff
> ==============================================================================
> --- couchdb/trunk/src/couchdb/couch_util.erl (original)
> +++ couchdb/trunk/src/couchdb/couch_util.erl Sun Jul 11 10:31:38 2010
> @@ -144,18 +144,11 @@ get_nested_json_value(Value, []) ->
> get_nested_json_value(_NotJSONObj, _) ->
> throw({not_found, json_mismatch}).
>
> -proplist_apply_field(H, L) ->
> - {R} = json_apply_field(H, {L}),
> - R.
> -
> -json_apply_field(H, {L}) ->
> - json_apply_field(H, L, []).
> -json_apply_field({Key, NewValue}, [{Key, _OldVal} | Headers], Acc) ->
> - json_apply_field({Key, NewValue}, Headers, Acc);
> -json_apply_field({Key, NewValue}, [{OtherKey, OtherVal} | Headers], Acc) ->
> - json_apply_field({Key, NewValue}, Headers, [{OtherKey, OtherVal} | Acc]);
> -json_apply_field({Key, NewValue}, [], Acc) ->
> - {[{Key, NewValue}|Acc]}.
> +proplist_apply_field({K, _V} = KV, L) ->
> + lists:keystore(K, 1, L, KV).
> +
> +json_apply_field({K, _V} = KV, {L}) ->
> + {lists:keystore(K, 1, L, KV)}.
>
> json_user_ctx(#db{name=DbName, user_ctx=Ctx}) ->
> {[{<<"db">>, DbName},
>
>
Re: svn commit: r963042 - /couchdb/trunk/src/couchdb/couch_util.erl
Posted by Filipe David Manana <fd...@apache.org>.
Hey Adam,
Hum, didn't notice before that only the first occurrence is stored with
lists:keystore/4.
My fault :(
I'll revert it.
cheers
On Mon, Jul 12, 2010 at 5:44 PM, Adam Kocoloski <ko...@apache.org> wrote:
> Hi Filipe, I thought about doing this once, but lists:keystore/4 only drops
> the first occurrence of K, whereas json_apply_field drops all matching
> occurrences. Do we care about the case where multiple values for e.g. the
> Vary header have been supplied by the user in a show function?
>
> Adam
>
> On Jul 11, 2010, at 6:31 AM, fdmanana@apache.org wrote:
>
> > Author: fdmanana
> > Date: Sun Jul 11 10:31:38 2010
> > New Revision: 963042
> >
> > URL: http://svn.apache.org/viewvc?rev=963042&view=rev
> > Log:
> > Removing unnecessary code.
> >
> > Modified:
> > couchdb/trunk/src/couchdb/couch_util.erl
> >
> > Modified: couchdb/trunk/src/couchdb/couch_util.erl
> > URL:
> http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_util.erl?rev=963042&r1=963041&r2=963042&view=diff
> >
> ==============================================================================
> > --- couchdb/trunk/src/couchdb/couch_util.erl (original)
> > +++ couchdb/trunk/src/couchdb/couch_util.erl Sun Jul 11 10:31:38 2010
> > @@ -144,18 +144,11 @@ get_nested_json_value(Value, []) ->
> > get_nested_json_value(_NotJSONObj, _) ->
> > throw({not_found, json_mismatch}).
> >
> > -proplist_apply_field(H, L) ->
> > - {R} = json_apply_field(H, {L}),
> > - R.
> > -
> > -json_apply_field(H, {L}) ->
> > - json_apply_field(H, L, []).
> > -json_apply_field({Key, NewValue}, [{Key, _OldVal} | Headers], Acc) ->
> > - json_apply_field({Key, NewValue}, Headers, Acc);
> > -json_apply_field({Key, NewValue}, [{OtherKey, OtherVal} | Headers], Acc)
> ->
> > - json_apply_field({Key, NewValue}, Headers, [{OtherKey, OtherVal} |
> Acc]);
> > -json_apply_field({Key, NewValue}, [], Acc) ->
> > - {[{Key, NewValue}|Acc]}.
> > +proplist_apply_field({K, _V} = KV, L) ->
> > + lists:keystore(K, 1, L, KV).
> > +
> > +json_apply_field({K, _V} = KV, {L}) ->
> > + {lists:keystore(K, 1, L, KV)}.
> >
> > json_user_ctx(#db{name=DbName, user_ctx=Ctx}) ->
> > {[{<<"db">>, DbName},
> >
> >
>
>
--
Filipe David Manana,
fdmanana@apache.org
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."