Skip to content

Commit dda4354

Browse files
Merge branch 'master' into include-cleanup
2 parents 2007688 + 3cedbfa commit dda4354

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

src/mfast/allocator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
// This file is part of mFAST.
55
// See the file license.txt for licensing information.
66
#include "allocator.h"
7+
#include "allocator_utils.h"
78
#include <cstring>
89

910
namespace mfast {
1011

11-
inline std::size_t align(std::size_t n, std::size_t x) {
12-
const std::size_t y = x - 1;
13-
return (n + y) & ~y;
14-
}
15-
1612
std::size_t allocator::reallocate(void *&pointer, std::size_t old_size,
1713
std::size_t new_size) {
1814
// make the new_size at least 64 bytes

src/mfast/allocator_utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#include <cstddef>
3+
4+
namespace mfast {
5+
6+
inline std::size_t align(std::size_t n, std::size_t x) {
7+
const std::size_t y = x - 1;
8+
return (n + y) & ~y;
9+
}
10+
11+
}

src/mfast/arena_allocator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
// This file is part of mFAST.
55
// See the file license.txt for licensing information.
66
#include "arena_allocator.h"
7+
#include "allocator_utils.h"
78
#include <cstring>
89
#include <cstdlib>
910
#include <new>
1011

1112
namespace mfast {
1213

13-
inline std::size_t align(std::size_t n, std::size_t x) {
14-
const std::size_t y = x - 1;
15-
return (n + y) & ~y;
16-
}
17-
1814
void arena_allocator::free_list(memory_chunk_base *head) {
1915
memory_chunk_base *tmp;
2016
while (head) {

src/mfast/xml_parser/FastXMLVisitor.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
// This file is part of mFAST.
55
// See the file license.txt for licensing information.
66
#include "FastXMLVisitor.h"
7+
#include "xml_util.h"
78
#include <cstring>
89
#include <cstdlib>
910
const char *FastXMLVisitor::get_optional_attr(const XMLElement &element,
1011
const char *attr_name,
1112
const char *default_value) const {
12-
const XMLAttribute *attr = element.FindAttribute(attr_name);
13-
if (attr == nullptr) {
14-
return default_value;
15-
}
16-
return attr->Value();
13+
return mfast::xml_parser::get_optional_attr(element, attr_name, default_value);
1714
}
1815

1916
bool FastXMLVisitor::is_mandatory_constant(const XMLElement &element) {

src/mfast/xml_parser/view_info_builder.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cstring>
22
#include "view_info_builder.h"
3+
#include "xml_util.h"
34
#include "../exceptions.h"
45
#include <algorithm>
56
namespace mfast {
@@ -157,16 +158,6 @@ void view_info_builder::visit(const set_field_instruction *inst,
157158
struct tag_reference_name;
158159
typedef boost::error_info<tag_reference_name, std::string> reference_name_info;
159160

160-
inline const char *get_optional_attr(const tinyxml2::XMLElement &element,
161-
const char *attr_name,
162-
const char *default_value) {
163-
const tinyxml2::XMLAttribute *attr = element.FindAttribute(attr_name);
164-
if (attr == nullptr) {
165-
return default_value;
166-
}
167-
return attr->Value();
168-
}
169-
170161
void view_info_builder::build_field_view(const tinyxml2::XMLElement &element,
171162
unsigned &max_depth,
172163
std::deque<field_view_info> &fields) {

src/mfast/xml_parser/xml_util.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ inline const char *get_optional_attr(const XMLElement &element,
1515
const char *attr_name,
1616
const char *default_value) {
1717
const XMLAttribute *attr = element.FindAttribute(attr_name);
18-
if (attr == nullptr) {
19-
return default_value;
20-
}
21-
return attr->Value();
18+
return attr ? attr->Value() : default_value;
2219
}
2320

2421
inline const char *string_dup(const char *str, arena_allocator &alloc) {

0 commit comments

Comments
 (0)