Skip to content

Commit 9c486da

Browse files
hjanetzektallytalwar
authored andcommitted
Better avoid unions of non-promitive types
1 parent 2026924 commit 9c486da

File tree

1 file changed

+6
-40
lines changed

1 file changed

+6
-40
lines changed

Diff for: core/include/tangram/platform.h

+6-40
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,17 @@ using FontSourceLoader = std::function<std::vector<char>()>;
3030

3131
struct FontSourceHandle {
3232

33+
FontSourceHandle() {}
34+
~FontSourceHandle() {}
35+
3336
explicit FontSourceHandle(Url path) : fontPath(path) { tag = FontPath; }
3437
explicit FontSourceHandle(std::string name) : fontName(name) { tag = FontName; }
3538
explicit FontSourceHandle(FontSourceLoader loader) : fontLoader(loader) { tag = FontLoader; }
36-
FontSourceHandle() {}
37-
38-
~FontSourceHandle() {
39-
using std::string;
40-
switch (tag) {
41-
case FontSourceHandle::FontPath:
42-
fontPath.~Url();
43-
break;
44-
case FontSourceHandle::FontName:
45-
fontName.~string();
46-
break;
47-
case FontSourceHandle::FontLoader:
48-
fontLoader.~FontSourceLoader();
49-
break;
50-
case FontSourceHandle::None:
51-
break;
52-
}
53-
}
54-
55-
FontSourceHandle(const FontSourceHandle& other) {
56-
tag = other.tag;
57-
switch (other.tag) {
58-
case FontSourceHandle::FontPath:
59-
fontPath = other.fontPath;
60-
break;
61-
case FontSourceHandle::FontName:
62-
fontName = other.fontName;
63-
break;
64-
case FontSourceHandle::FontLoader:
65-
fontLoader = other.fontLoader;
66-
break;
67-
case FontSourceHandle::None:
68-
break;
69-
}
70-
}
7139

7240
enum { FontPath, FontName, FontLoader, None } tag = None;
73-
union {
74-
Url fontPath;
75-
std::string fontName;
76-
FontSourceLoader fontLoader;
77-
};
41+
Url fontPath;
42+
std::string fontName;
43+
FontSourceLoader fontLoader;
7844

7945
bool isValid() const { return tag != None; }
8046
};

0 commit comments

Comments
 (0)