Skip to content

Commit 805bcbe

Browse files
authored
drop LEX_STRING from VDF arg/return (#420)
* drop LEX_STRING from VDF arg/return helpers (#415) ValidateAndConvertVDFArguments immediately decomposed const LEX_STRING& extension_name into a std::string at line 1280, used only to satisfy make_qualified_base_name and ResolveTypeToContext. SetVDFReturnTypeContext wrapped its parameter via to_string_view() at the inner ResolveTypeToContext call instead of the outer boundary. Take std::string_view directly in both so callers do the conversion once via to_string_view() from include/lex_string.h. Follow-up to #412; surfaced in #257 review thread. * format: fix clang-format wrapping in #415 CI villint flagged two line-wrap nits caused by the longer extension_name / to_string_view(...) text replacing ext_name / m_udf->extension_name in #415.
1 parent 60b9974 commit 805bcbe

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

villagesql/types/util.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ void ClearAlterCustomFields(THD *thd) {
12511251
}
12521252

12531253
bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
1254-
const LEX_STRING &extension_name,
1254+
std::string_view extension_name,
12551255
uint arg_count, Item **args,
12561256
const vef_signature_t *signature,
12571257
TypeParameters *out_return_params) {
@@ -1277,7 +1277,6 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
12771277
uint arg_index;
12781278
};
12791279
std::map<std::string, KnownEntry> known_params;
1280-
const std::string ext_name(extension_name.str, extension_name.length);
12811280

12821281
for (uint i = 0; i < arg_count; i++) {
12831282
const vef_type_t &expected_type = signature->params[i];
@@ -1286,7 +1285,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
12861285

12871286
assert(expected_type.custom_type != nullptr);
12881287
const std::string expected_qbn =
1289-
make_qualified_base_name(ext_name, expected_type.custom_type);
1288+
make_qualified_base_name(extension_name, expected_type.custom_type);
12901289

12911290
auto *tc = args[i]->get_type_context();
12921291
if (tc == nullptr) continue; // String constants handled in pass 2
@@ -1329,7 +1328,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
13291328

13301329
assert(expected_type.custom_type != nullptr);
13311330
const std::string expected_qbn =
1332-
make_qualified_base_name(ext_name, expected_type.custom_type);
1331+
make_qualified_base_name(extension_name, expected_type.custom_type);
13331332

13341333
auto *tc = args[i]->get_type_context();
13351334

@@ -1343,7 +1342,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
13431342
auto it = known_params.find(expected_qbn);
13441343
if (it != known_params.end()) {
13451344
const TypeContext *resolved_tc = nullptr;
1346-
if (ResolveTypeToContext(ext_name, expected_type.custom_type,
1345+
if (ResolveTypeToContext(extension_name, expected_type.custom_type,
13471346
*it->second.params, *thd->mem_root,
13481347
resolved_tc)) {
13491348
return true;
@@ -1374,7 +1373,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
13741373
}
13751374

13761375
const TypeContext *type_ctx = nullptr;
1377-
if (ResolveTypeToContext(ext_name, expected_type.custom_type,
1376+
if (ResolveTypeToContext(extension_name, expected_type.custom_type,
13781377
resolved_params, *thd->mem_root, type_ctx)) {
13791378
return true;
13801379
}
@@ -1416,8 +1415,8 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
14161415
if (out_return_params != nullptr &&
14171416
signature->return_type.id == VEF_TYPE_CUSTOM &&
14181417
signature->return_type.custom_type != nullptr) {
1419-
const std::string return_qbn =
1420-
make_qualified_base_name(ext_name, signature->return_type.custom_type);
1418+
const std::string return_qbn = make_qualified_base_name(
1419+
extension_name, signature->return_type.custom_type);
14211420
auto it = known_params.find(return_qbn);
14221421
if (it != known_params.end()) {
14231422
*out_return_params = *it->second.params;
@@ -1427,7 +1426,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
14271426
return false;
14281427
}
14291428

1430-
void SetVDFReturnTypeContext(THD *thd, const LEX_STRING &extension_name,
1429+
void SetVDFReturnTypeContext(THD *thd, std::string_view extension_name,
14311430
const vef_signature_t *signature,
14321431
Item *result_item,
14331432
const TypeParameters *return_params) {
@@ -1437,7 +1436,7 @@ void SetVDFReturnTypeContext(THD *thd, const LEX_STRING &extension_name,
14371436
}
14381437

14391438
const TypeContext *return_type_ctx = nullptr;
1440-
if (!ResolveTypeToContext(to_string_view(extension_name), return_type_name,
1439+
if (!ResolveTypeToContext(extension_name, return_type_name,
14411440
return_params ? *return_params : TypeParameters{},
14421441
*thd->mem_root, return_type_ctx) &&
14431442
return_type_ctx != nullptr) {

villagesql/types/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ extern bool CheckCustomTypeUsage(Item *item, THD *thd);
378378
// the same as those matching arguements of the same abstract type). Returns
379379
// false on success, true on error.
380380
extern bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
381-
const LEX_STRING &extension_name,
381+
std::string_view extension_name,
382382
uint arg_count, Item **args,
383383
const vef_signature_t *signature,
384384
TypeParameters *out_return_params);
385385

386386
// Set the return type_context on a VDF result Item if it returns a custom type.
387387
// If return_params is non-null, uses those params instead of empty ones.
388-
extern void SetVDFReturnTypeContext(THD *thd, const LEX_STRING &extension_name,
388+
extern void SetVDFReturnTypeContext(THD *thd, std::string_view extension_name,
389389
const vef_signature_t *signature,
390390
Item *result_item,
391391
const TypeParameters *return_params);

villagesql/vdf/vdf_handler.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <type_traits>
1919

20+
#include "lex_string.h"
2021
#include "my_sys.h"
2122
#include "mysql/strings/m_ctype.h"
2223
#include "sql/current_thd.h"
@@ -98,8 +99,8 @@ bool vdf_handler::fix_fields(THD *thd [[maybe_unused]],
9899
villagesql::TypeParameters return_params;
99100
if (signature != nullptr &&
100101
villagesql::ValidateAndConvertVDFArguments(
101-
thd, m_udf->name.str, m_udf->extension_name, arg_count, m_args,
102-
signature, &return_params)) {
102+
thd, m_udf->name.str, to_string_view(m_udf->extension_name),
103+
arg_count, m_args, signature, &return_params)) {
103104
return true;
104105
}
105106

@@ -171,8 +172,9 @@ bool vdf_handler::fix_fields(THD *thd [[maybe_unused]],
171172
// return_params inferred from args via the call to
172173
// ValidateAndConvertVDFArguments.
173174
if (signature != nullptr && signature->return_type.id == VEF_TYPE_CUSTOM) {
174-
villagesql::SetVDFReturnTypeContext(thd, m_udf->extension_name, signature,
175-
func, &return_params);
175+
villagesql::SetVDFReturnTypeContext(thd,
176+
to_string_view(m_udf->extension_name),
177+
signature, func, &return_params);
176178
m_return_type_context = func->get_type_context();
177179
}
178180

0 commit comments

Comments
 (0)