Permalink
Browse files

change actors by process dictionary (7-10x faster)

  • Loading branch information...
manuel-rubio committed Jun 23, 2014
1 parent f27b111 commit ad3ae9897553e6bd77403501264e2c1df1bfcff7
Showing with 226 additions and 572 deletions.
  1. +12 −56 src/ephp_const.erl
  2. +117 −216 src/ephp_context.erl
  3. +19 −66 src/ephp_func.erl
  4. +19 −65 src/ephp_include.erl
  5. +35 −82 src/ephp_output.erl
  6. +23 −79 src/ephp_vars.erl
  7. +1 −8 test/ephp_context_test.erl
View
@@ -1,15 +1,9 @@
-module(ephp_const).
-behaviour(gen_server).
-define(SERVER, ?MODULE).
-compile([warnings_as_errors]).
-include("ephp.hrl").
-record(state, {
const = ?DICT:new() :: dict()
}).
%% ------------------------------------------------------------------
%% API Function Exports
%% ------------------------------------------------------------------
@@ -21,64 +15,26 @@
destroy/1
]).
%% ------------------------------------------------------------------
%% gen_server Function Exports
%% ------------------------------------------------------------------
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------
start_link() ->
gen_server:start_link(?MODULE, [], []).
get(Const, Name) ->
gen_server:call(Const, {get, Name}).
set(Const, Name, Value) ->
gen_server:cast(Const, {set, Name, Value}).
destroy(Const) ->
gen_server:cast(Const, stop).
%% ------------------------------------------------------------------
%% gen_server Function Definitions
%% ------------------------------------------------------------------
init([]) ->
{ok, #state{}}.
Ref = make_ref(),
erlang:put(Ref, ?DICT:new()),
{ok, Ref}.
handle_call({get, Name}, _From, #state{const=Const}=State) ->
{reply, case ?DICT:find(Name, Const) of
get(Ref, Name) ->
Const = erlang:get(Ref),
case ?DICT:find(Name, Const) of
{ok, Value} -> Value;
error -> Name
end, State};
handle_call(_Request, _From, State) ->
{reply, ok, State}.
handle_cast({set, Name, Value}, #state{const=Const}=State) ->
NewConst = ?DICT:store(Name, Value, Const),
{noreply, State#state{const=NewConst}};
handle_cast(stop, State) ->
{stop, normal, State};
handle_cast(_Msg, State) ->
{noreply, State}.
end.
handle_info(_Info, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
set(Ref, Name, Value) ->
Const = erlang:get(Ref),
put(Ref, ?DICT:store(Name, Value, Const)),
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%% ------------------------------------------------------------------
%% Internal Function Definitions
%% ------------------------------------------------------------------
destroy(Const) ->
erlang:erase(Const).
Oops, something went wrong.

0 comments on commit ad3ae98

Please sign in to comment.