MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ChangeIds

Function ChangeIds

Source/Engine/Serialization/JsonTools.cpp:11–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "Engine/Utilities/Encryption.h"
10
11void ChangeIds(rapidjson_flax::Value& obj, rapidjson_flax::Document& document, const Dictionary<Guid, Guid>& mapping)
12{
13 if (obj.IsObject())
14 {
15 for (rapidjson_flax::Value::MemberIterator i = obj.MemberBegin(); i != obj.MemberEnd(); ++i)
16 {
17 ChangeIds(i->value, document, mapping);
18 }
19 }
20 else if (obj.IsArray())
21 {
22 for (rapidjson::SizeType i = 0; i < obj.Size(); i++)
23 {
24 ChangeIds(obj[i], document, mapping);
25 }
26 }
27 else if (obj.IsString() && obj.GetStringLength() == 32)
28 {
29 auto value = JsonTools::GetGuid(obj);
30 if (value.IsValid() && mapping.TryGet(value, value))
31 {
32 // Unoptimized version:
33 //obj.SetString(value.ToString(Guid::FormatType::N).ToSTD().c_str(), 32, document.GetAllocator());
34
35 // Optimized version:
36 char buffer[32] =
37 {
38 // @formatter:off
39 '0','0','0','0','0','0','0','0','0','0',
40 '0','0','0','0','0','0','0','0','0','0',
41 '0','0','0','0','0','0','0','0','0','0',
42 '0','0'
43 // @formatter:on
44 };
45 static const char* digits = "0123456789abcdef";
46 uint32 n = value.A;
47 char* p = buffer + 7;
48 do
49 {
50 *p-- = digits[n & 0xf];
51 } while ((n >>= 4) != 0);
52 n = value.B;
53 p = buffer + 15;
54 do
55 {
56 *p-- = digits[n & 0xf];
57 } while ((n >>= 4) != 0);
58 n = value.C;
59 p = buffer + 23;
60 do
61 {
62 *p-- = digits[n & 0xf];
63 } while ((n >>= 4) != 0);
64 n = value.D;
65 p = buffer + 31;
66 do
67 {
68 *p-- = digits[n & 0xf];

Callers 4

ChangeIdMethod · 0.85
ApplyAllInternalMethod · 0.85
CreatePrefabMethod · 0.85
ChangeIdsMethod · 0.85

Calls 9

GetGuidFunction · 0.85
MemberBeginMethod · 0.80
MemberEndMethod · 0.80
SetStringMethod · 0.80
GetAllocatorMethod · 0.80
SizeMethod · 0.45
GetStringLengthMethod · 0.45
IsValidMethod · 0.45
TryGetMethod · 0.45

Tested by

no test coverage detected