refactor(ds): Use inline functions instead of macros
This commit is contained in:
parent
a11e75d189
commit
7f408da251
|
@ -121,7 +121,15 @@
|
||||||
|
|
||||||
-export_type([db/0, iterator/0, schema/0]).
|
-export_type([db/0, iterator/0, schema/0]).
|
||||||
|
|
||||||
-compile({inline, [ones/1, bitwise_concat/3]}).
|
-compile(
|
||||||
|
{inline, [
|
||||||
|
bitwise_concat/3,
|
||||||
|
ones/1,
|
||||||
|
successor/1,
|
||||||
|
topic_hash_matches/3,
|
||||||
|
time_matches/3
|
||||||
|
]}
|
||||||
|
).
|
||||||
|
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
%% Type declarations
|
%% Type declarations
|
||||||
|
@ -343,14 +351,6 @@ restore_iterator(DB, #{
|
||||||
%% Internal exports
|
%% Internal exports
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
-define(topic_hash_matches(Bitstring, HashBitfilter, HashBitmask),
|
|
||||||
(Bitstring band HashBitmask) == HashBitfilter
|
|
||||||
).
|
|
||||||
|
|
||||||
-define(time_matches(Bitstring, TimeBitfilter, TimeBitmask),
|
|
||||||
(Bitstring band TimeBitmask) >= TimeBitfilter
|
|
||||||
).
|
|
||||||
|
|
||||||
-spec bitsize(keymapper()) -> bits().
|
-spec bitsize(keymapper()) -> bits().
|
||||||
bitsize(#keymapper{bitsize = Bitsize}) ->
|
bitsize(#keymapper{bitsize = Bitsize}) ->
|
||||||
Bitsize.
|
Bitsize.
|
||||||
|
@ -424,8 +424,8 @@ compute_next_seek(
|
||||||
time_bitmask = TimeBitmask
|
time_bitmask = TimeBitmask
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
HashMatches = ?topic_hash_matches(Bitstring, HashBitfilter, HashBitmask),
|
HashMatches = topic_hash_matches(Bitstring, HashBitfilter, HashBitmask),
|
||||||
TimeMatches = ?time_matches(Bitstring, TimeBitfilter, TimeBitmask),
|
TimeMatches = time_matches(Bitstring, TimeBitfilter, TimeBitmask),
|
||||||
compute_next_seek(HashMatches, TimeMatches, Bitstring, Filter).
|
compute_next_seek(HashMatches, TimeMatches, Bitstring, Filter).
|
||||||
|
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
@ -508,8 +508,8 @@ match_next(
|
||||||
time_bitmask = TimeBitmask
|
time_bitmask = TimeBitmask
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
HashMatches = ?topic_hash_matches(Bitstring, HashBitfilter, HashBitmask),
|
HashMatches = topic_hash_matches(Bitstring, HashBitfilter, HashBitmask),
|
||||||
TimeMatches = ?time_matches(Bitstring, TimeBitfilter, TimeBitmask),
|
TimeMatches = time_matches(Bitstring, TimeBitfilter, TimeBitmask),
|
||||||
case HashMatches and TimeMatches of
|
case HashMatches and TimeMatches of
|
||||||
true ->
|
true ->
|
||||||
Message = {Topic, _Payload} = unwrap_message_value(Value),
|
Message = {Topic, _Payload} = unwrap_message_value(Value),
|
||||||
|
@ -541,7 +541,7 @@ compute_next_seek(
|
||||||
none ->
|
none ->
|
||||||
none;
|
none;
|
||||||
_ ->
|
_ ->
|
||||||
TimeMatches = ?time_matches(NextBitstring, TimeBitfilter, TimeBitmask),
|
TimeMatches = time_matches(NextBitstring, TimeBitfilter, TimeBitmask),
|
||||||
compute_next_seek(true, TimeMatches, NextBitstring, Filter)
|
compute_next_seek(true, TimeMatches, NextBitstring, Filter)
|
||||||
end;
|
end;
|
||||||
%% `Bitstring` is out of the time range defined by `TimeBitfilter`.
|
%% `Bitstring` is out of the time range defined by `TimeBitfilter`.
|
||||||
|
@ -558,6 +558,12 @@ compute_next_seek(
|
||||||
compute_next_seek(true, true, Bitstring, _It) ->
|
compute_next_seek(true, true, Bitstring, _It) ->
|
||||||
Bitstring.
|
Bitstring.
|
||||||
|
|
||||||
|
topic_hash_matches(Bitstring, HashBitfilter, HashBitmask) ->
|
||||||
|
(Bitstring band HashBitmask) == HashBitfilter.
|
||||||
|
|
||||||
|
time_matches(Bitstring, TimeBitfilter, TimeBitmask) ->
|
||||||
|
(Bitstring band TimeBitmask) >= TimeBitfilter.
|
||||||
|
|
||||||
compute_time_seek(Bitstring, TimeBitfilter, TimeBitmask) ->
|
compute_time_seek(Bitstring, TimeBitfilter, TimeBitmask) ->
|
||||||
% Replace the bits of the timestamp in `Bistring` with bits from `Timebitfilter`.
|
% Replace the bits of the timestamp in `Bistring` with bits from `Timebitfilter`.
|
||||||
(Bitstring band (bnot TimeBitmask)) bor TimeBitfilter.
|
(Bitstring band (bnot TimeBitmask)) bor TimeBitfilter.
|
||||||
|
|
Loading…
Reference in New Issue