MDEV-20674 Reuse val_native() in ExtractValue() and UpdateXML()

This commit is contained in:
Alexander Barkov 2019-09-26 11:06:54 +04:00
commit 08de2540ac
3 changed files with 141 additions and 150 deletions

View file

@ -2,6 +2,7 @@
#define ITEM_XMLFUNC_INCLUDED
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2009, 2019, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -23,6 +24,42 @@
typedef struct my_xml_node_st MY_XML_NODE;
/* Structure to store nodeset elements */
class MY_XPATH_FLT
{
public:
uint num; // Absolute position in MY_XML_NODE array
uint pos; // Relative position in context
uint size; // Context size
public:
MY_XPATH_FLT(uint32 num_arg, uint32 pos_arg)
:num(num_arg), pos(pos_arg), size(0)
{ }
MY_XPATH_FLT(uint32 num_arg, uint32 pos_arg, uint32 size_arg)
:num(num_arg), pos(pos_arg), size(size_arg)
{ }
bool append_to(Native *to) const
{
return to->append((const char*) this, (uint32) sizeof(*this));
}
};
class NativeNodesetBuffer: public NativeBuffer<16*sizeof(MY_XPATH_FLT)>
{
public:
const MY_XPATH_FLT &element(uint i) const
{
const MY_XPATH_FLT *p= (MY_XPATH_FLT*) (ptr() + i * sizeof(MY_XPATH_FLT));
return *p;
}
uint32 elements() const
{
return length() / sizeof(MY_XPATH_FLT);
}
};
class Item_xml_str_func: public Item_str_func
{
protected:
@ -103,7 +140,8 @@ public:
class Item_func_xml_update: public Item_xml_str_func
{
String tmp_value2, tmp_value3;
NativeNodesetBuffer tmp_native_value2;
String tmp_value3;
bool collect_result(String *str,
const MY_XML_NODE *cut,
const String *replace);