[
https://issues.apache.org/jira/browse/THRIFT-4270?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16109215#comment-16109215
]
ASF GitHub Bot commented on THRIFT-4270:
----------------------------------------
Github user dhull commented on the issue:
https://github.com/apache/thrift/pull/1320
@djnym, thanks for pointing out my build problem. I had developed the code
in this pull request on top of my code for #1319 but thought it would be better
to separate it back out for the pull request; unfortunately I made a mistake.
I have fixed the problem and rebased on the current HEAD and the tests are
now passing.
> Generate Erlang mapping functions for const maps and lists
> ----------------------------------------------------------
>
> Key: THRIFT-4270
> URL: https://issues.apache.org/jira/browse/THRIFT-4270
> Project: Thrift
> Issue Type: Improvement
> Components: Erlang - Compiler
> Affects Versions: 0.10.0
> Reporter: David Hull
> Priority: Minor
>
> The Thrift Erlang compiler generates macros for consts. This is great for
> scalar types and structs. However the macro that is generated for a map is
> something like
> {code:none}
> -define(CONSTANTS_DEMO_GEN_MAP, dict:from_list([{35532,233},{43523,853}])).
> {code}
> This is not as useful as the other macros, because any use of this macro will
> generate the dict at run time. (It is possible to work around this issue by
> using the ct_expand parse transform.)
> It would be better to generate a function directly to do the transform. The
> function for the previous example would be
> {code:none}
> gen_map(35532) -> 233;
> gen_map(43523) -> 853.
> {code}
> Similarly, the macro that is generated for a list is something like:
> {code:none}
> -define(CONSTANTS_DEMO_GEN_LIST, [235235,23598352,3253523]).
> {code}
> This representation is fine if you want to iterate over the elements of the
> list, but is not efficient if you need to look an element because lists in
> Erlang are implemented as singly-linked lists. For lookups, it would be
> better to generate a tuple and then use {{element(N, Tuple)}} to extract the
> nth element.
> The thrift generator could generate a function to do the lookup:
> {code:none}
> gen_list(N) -> element(N, {235235,23598352,3253523}).
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)