From: Jens Geyer Date: Sun, 16 Mar 2014 14:48:53 +0000 (+0200) Subject: THRIFT-2404 emit warning on (typically inefficient) list X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=6fe77e8e660139dbe7ad2b52e5ca3d0e5a0de7ca;p=common%2Fthrift.git THRIFT-2404 emit warning on (typically inefficient) list Patch: Jens Geyer --- diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 781db3b4..e1c93948 100755 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -661,6 +661,20 @@ void generate_all_fingerprints(t_program* program) { */ } + +/** + * Emits a warning on list, binary type is typically a much better choice. + */ +void check_for_list_of_bytes(t_type* list_elem_type) { + if((g_parse_mode == PROGRAM) && (list_elem_type != NULL) && list_elem_type->is_base_type()) { + t_base_type* tbase = (t_base_type*)list_elem_type; + if(tbase->get_base() == t_base_type::TYPE_BYTE) { + pwarning(1,"Consider using the more efficient \"binary\" type instead of \"list\"."); + } + } +} + + /** * Prints the version number */ diff --git a/compiler/cpp/src/main.h b/compiler/cpp/src/main.h index 87af5f6e..f737e3fe 100644 --- a/compiler/cpp/src/main.h +++ b/compiler/cpp/src/main.h @@ -88,6 +88,10 @@ char* clean_up_doctext(char* doctext); */ void declare_valid_program_doctext(); +/** + * Emits a warning on list, binary type is typically a much better choice. + */ +void check_for_list_of_bytes(t_type* list_elem_type); /** * Flex utilities diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index fd72b700..7c4a90bb 100755 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -1213,6 +1213,7 @@ ListType: tok_list '<' FieldType '>' CppType { pdebug("ListType -> tok_list"); + check_for_list_of_bytes($3); $$ = new t_list($3); if ($5 != NULL) { ((t_container*)$$)->set_cpp_name(std::string($5));