@@ -356,11 +356,10 @@ Local<Value> NbtByteClass::pack(ByteTag* tag, bool noDelete) {
356
356
try {
357
357
if (noDelete) // unique_ptr 共享指针 + noDelete
358
358
{
359
- std::unique_ptr<ByteTag> nbt (tag);
360
- auto * nbtObj = new NbtByteClass (std::move (nbt));
361
- nbtObj->canDelete = false ;
359
+ NbtByteClass* nbtObj = new NbtByteClass (std::unique_ptr<ByteTag>(tag));
360
+ nbtObj->canDelete = false ;
362
361
return nbtObj->getScriptObject ();
363
- } else return (new NbtByteClass (std::make_unique <ByteTag>(tag-> as <ByteTag>() )))->getScriptObject ();
362
+ } else return (new NbtByteClass (std::unique_ptr <ByteTag>(tag)))->getScriptObject ();
364
363
}
365
364
CATCH (" Fail in construct NbtByte!" );
366
365
}
@@ -428,11 +427,10 @@ Local<Value> NbtIntClass::pack(IntTag* tag, bool noDelete) {
428
427
try {
429
428
if (noDelete) // unique_ptr 共享指针 + noDelete
430
429
{
431
- std::unique_ptr<IntTag> nbt (tag);
432
- auto * nbtObj = new NbtIntClass (std::move (nbt));
433
- nbtObj->canDelete = false ;
430
+ NbtIntClass* nbtObj = new NbtIntClass (std::unique_ptr<IntTag>(tag));
431
+ nbtObj->canDelete = false ;
434
432
return nbtObj->getScriptObject ();
435
- } else return (new NbtIntClass (std::make_unique <IntTag>(tag-> as <IntTag>() )))->getScriptObject ();
433
+ } else return (new NbtIntClass (std::unique_ptr <IntTag>(tag)))->getScriptObject ();
436
434
}
437
435
CATCH (" Fail in construct NbtInt!" );
438
436
}
@@ -501,11 +499,10 @@ Local<Value> NbtShortClass::pack(ShortTag* tag, bool noDelete) {
501
499
try {
502
500
if (noDelete) // unique_ptr 共享指针 + noDelete
503
501
{
504
- std::unique_ptr<ShortTag> nbt (tag);
505
- auto * nbtObj = new NbtShortClass (std::move (nbt));
506
- nbtObj->canDelete = false ;
502
+ NbtShortClass* nbtObj = new NbtShortClass (std::unique_ptr<ShortTag>(tag));
503
+ nbtObj->canDelete = false ;
507
504
return nbtObj->getScriptObject ();
508
- } else return (new NbtShortClass (std::make_unique <ShortTag>(tag-> as <ShortTag>() )))->getScriptObject ();
505
+ } else return (new NbtShortClass (std::unique_ptr <ShortTag>(tag)))->getScriptObject ();
509
506
}
510
507
CATCH (" Fail in construct NbtShort!" );
511
508
}
@@ -573,11 +570,10 @@ Local<Value> NbtLongClass::pack(Int64Tag* tag, bool noDelete) {
573
570
try {
574
571
if (noDelete) // unique_ptr 共享指针 + noDelete
575
572
{
576
- std::unique_ptr<Int64Tag> nbt (tag);
577
- auto * nbtObj = new NbtLongClass (std::move (nbt));
578
- nbtObj->canDelete = false ;
573
+ NbtLongClass* nbtObj = new NbtLongClass (std::unique_ptr<Int64Tag>(tag));
574
+ nbtObj->canDelete = false ;
579
575
return nbtObj->getScriptObject ();
580
- } else return (new NbtLongClass (std::make_unique <Int64Tag>(tag-> as <Int64Tag>() )))->getScriptObject ();
576
+ } else return (new NbtLongClass (std::unique_ptr <Int64Tag>(tag)))->getScriptObject ();
581
577
}
582
578
CATCH (" Fail in construct NbtLong!" );
583
579
}
@@ -646,11 +642,10 @@ Local<Value> NbtFloatClass::pack(FloatTag* tag, bool noDelete) {
646
642
try {
647
643
if (noDelete) // unique_ptr 共享指针 + noDelete
648
644
{
649
- std::unique_ptr<FloatTag> nbt (tag);
650
- auto * nbtObj = new NbtFloatClass (std::move (nbt));
651
- nbtObj->canDelete = false ;
645
+ NbtFloatClass* nbtObj = new NbtFloatClass (std::unique_ptr<FloatTag>(tag));
646
+ nbtObj->canDelete = false ;
652
647
return nbtObj->getScriptObject ();
653
- } else return (new NbtFloatClass (std::make_unique <FloatTag>(tag-> as <FloatTag>() )))->getScriptObject ();
648
+ } else return (new NbtFloatClass (std::unique_ptr <FloatTag>(tag)))->getScriptObject ();
654
649
}
655
650
CATCH (" Fail in construct NbtFloat!" );
656
651
}
@@ -719,11 +714,10 @@ Local<Value> NbtDoubleClass::pack(DoubleTag* tag, bool noDelete) {
719
714
try {
720
715
if (noDelete) // unique_ptr 共享指针 + noDelete
721
716
{
722
- std::unique_ptr<DoubleTag> nbt (tag);
723
- auto * nbtObj = new NbtDoubleClass (std::move (nbt));
724
- nbtObj->canDelete = false ;
717
+ NbtDoubleClass* nbtObj = new NbtDoubleClass (std::unique_ptr<DoubleTag>(tag));
718
+ nbtObj->canDelete = false ;
725
719
return nbtObj->getScriptObject ();
726
- } else return (new NbtDoubleClass (std::make_unique <DoubleTag>(tag-> as <DoubleTag>() )))->getScriptObject ();
720
+ } else return (new NbtDoubleClass (std::unique_ptr <DoubleTag>(tag)))->getScriptObject ();
727
721
}
728
722
CATCH (" Fail in construct NbtDouble!" );
729
723
}
@@ -792,11 +786,10 @@ Local<Value> NbtStringClass::pack(StringTag* tag, bool noDelete) {
792
786
try {
793
787
if (noDelete) // unique_ptr 共享指针 + noDelete
794
788
{
795
- std::unique_ptr<StringTag> nbt (tag);
796
- auto * nbtObj = new NbtStringClass (std::move (nbt));
797
- nbtObj->canDelete = false ;
789
+ NbtStringClass* nbtObj = new NbtStringClass (std::unique_ptr<StringTag>(tag));
790
+ nbtObj->canDelete = false ;
798
791
return nbtObj->getScriptObject ();
799
- } else return (new NbtStringClass (std::make_unique <StringTag>(tag-> as <StringTag>() )))->getScriptObject ();
792
+ } else return (new NbtStringClass (std::unique_ptr <StringTag>(tag)))->getScriptObject ();
800
793
}
801
794
CATCH (" Fail in construct NbtString!" );
802
795
}
@@ -871,12 +864,10 @@ Local<Value> NbtByteArrayClass::pack(ByteArrayTag* tag, bool noDelete) {
871
864
try {
872
865
if (noDelete) // unique_ptr 共享指针 + noDelete
873
866
{
874
- std::unique_ptr<ByteArrayTag> nbt (tag);
875
- auto * nbtObj = new NbtByteArrayClass (std::move (nbt));
876
- nbtObj->canDelete = false ;
867
+ NbtByteArrayClass* nbtObj = new NbtByteArrayClass (std::unique_ptr<ByteArrayTag>(tag));
868
+ nbtObj->canDelete = false ;
877
869
return nbtObj->getScriptObject ();
878
- } else
879
- return (new NbtByteArrayClass (std::make_unique<ByteArrayTag>(tag->as <ByteArrayTag>())))->getScriptObject ();
870
+ } else return (new NbtByteArrayClass (std::unique_ptr<ByteArrayTag>(tag)))->getScriptObject ();
880
871
}
881
872
CATCH (" Fail in construct NbtByteArray!" );
882
873
}
@@ -1002,9 +993,8 @@ Local<Value> NbtListClass::pack(ListTag* tag, bool noDelete) {
1002
993
try {
1003
994
if (noDelete) // unique_ptr 共享指针 + noDelete
1004
995
{
1005
- std::unique_ptr<ListTag> nbt (tag);
1006
- auto * nbtObj = new NbtListClass (std::move (nbt));
1007
- nbtObj->canDelete = false ;
996
+ NbtListClass* nbtObj = new NbtListClass (std::unique_ptr<ListTag>(tag));
997
+ nbtObj->canDelete = false ;
1008
998
return nbtObj->getScriptObject ();
1009
999
} else return (new NbtListClass (std::unique_ptr<ListTag>(tag)))->getScriptObject ();
1010
1000
}
@@ -1399,8 +1389,7 @@ Local<Value> NbtListClass::getTag(const Arguments& args) {
1399
1389
res = NbtListClass::pack (nbt->at (index)->as_ptr <ListTag>(), true ); // share ptr
1400
1390
break ;
1401
1391
case Tag::Type::Compound:
1402
- res = NbtCompoundClass::pack (nbt->at (index)->as_ptr <CompoundTag>(),
1403
- true ); // share ptr
1392
+ res = NbtCompoundClass::pack (nbt->at (index)->as_ptr <CompoundTag>(), true ); // share ptr
1404
1393
break ;
1405
1394
case Tag::Type::End:
1406
1395
default :
@@ -1503,9 +1492,8 @@ Local<Value> NbtCompoundClass::pack(CompoundTag* tag, bool noDelete) {
1503
1492
try {
1504
1493
if (noDelete) // unique_ptr 共享指针 + noDelete
1505
1494
{
1506
- std::unique_ptr<CompoundTag> nbt (tag);
1507
- auto * nbtObj = new NbtCompoundClass (std::move (nbt));
1508
- nbtObj->canDelete = false ;
1495
+ NbtCompoundClass* nbtObj = new NbtCompoundClass (std::unique_ptr<CompoundTag>(tag));
1496
+ nbtObj->canDelete = false ;
1509
1497
return nbtObj->getScriptObject ();
1510
1498
} else return (new NbtCompoundClass (std::unique_ptr<CompoundTag>(tag)))->getScriptObject ();
1511
1499
}
@@ -1872,88 +1860,88 @@ Local<Value> NbtStatic::newTag(const Arguments& args) {
1872
1860
Local<Value> res;
1873
1861
switch (type) {
1874
1862
case Tag::Type::Byte: {
1875
- ByteTag tag (0 );
1863
+ auto tag = std::make_unique<ByteTag> (0 );
1876
1864
if (args.size () >= 2 && args[1 ].isNumber ()) {
1877
- tag = ByteTag (args[1 ].toInt ());
1865
+ * tag = ByteTag (args[1 ].toInt ());
1878
1866
}
1879
- res = NbtByteClass::pack (std::move (& tag));
1867
+ res = NbtByteClass::pack (std::move (tag));
1880
1868
break ;
1881
1869
}
1882
1870
case Tag::Type::Short: {
1883
- ShortTag tag (0 );
1871
+ auto tag = std::make_unique<ShortTag> (0 );
1884
1872
if (args.size () >= 2 && args[1 ].isNumber ()) {
1885
- tag. data = args[1 ].toInt ();
1873
+ tag-> data = args[1 ].toInt ();
1886
1874
}
1887
- res = NbtShortClass::pack (std::move (& tag));
1875
+ res = NbtShortClass::pack (std::move (tag));
1888
1876
break ;
1889
1877
}
1890
1878
case Tag::Type::Int: {
1891
- IntTag tag (0 );
1879
+ auto tag = std::make_unique<IntTag> (0 );
1892
1880
if (args.size () >= 2 && args[1 ].isNumber ()) {
1893
- tag. data = args[1 ].toInt ();
1881
+ tag-> data = args[1 ].toInt ();
1894
1882
}
1895
- res = NbtIntClass::pack (std::move (& tag));
1883
+ res = NbtIntClass::pack (std::move (tag));
1896
1884
break ;
1897
1885
}
1898
1886
case Tag::Type::Int64: {
1899
- Int64Tag tag (0 );
1887
+ auto tag = std::make_unique<Int64Tag> (0 );
1900
1888
if (args.size () >= 2 && args[1 ].isNumber ()) {
1901
- tag. data = args[1 ].asNumber ().toInt64 ();
1889
+ tag-> data = args[1 ].asNumber ().toInt64 ();
1902
1890
}
1903
- res = NbtLongClass::pack (std::move (& tag));
1891
+ res = NbtLongClass::pack (std::move (tag));
1904
1892
break ;
1905
1893
}
1906
1894
case Tag::Type::Float: {
1907
- FloatTag tag;
1895
+ auto tag = std::make_unique<FloatTag>() ;
1908
1896
if (args.size () >= 2 && args[1 ].isNumber ()) {
1909
- tag. data = args[1 ].asNumber ().toFloat ();
1897
+ tag-> data = args[1 ].asNumber ().toFloat ();
1910
1898
}
1911
- res = NbtFloatClass::pack (std::move (& tag));
1899
+ res = NbtFloatClass::pack (std::move (tag));
1912
1900
break ;
1913
1901
}
1914
1902
case Tag::Type::Double: {
1915
- DoubleTag tag;
1903
+ auto tag = std::make_unique<DoubleTag>() ;
1916
1904
if (args.size () >= 2 && args[1 ].isNumber ()) {
1917
- tag. data = args[1 ].asNumber ().toDouble ();
1905
+ tag-> data = args[1 ].asNumber ().toDouble ();
1918
1906
}
1919
- res = NbtDoubleClass::pack (std::move (& tag));
1907
+ res = NbtDoubleClass::pack (std::move (tag));
1920
1908
break ;
1921
1909
}
1922
1910
case Tag::Type::String: {
1923
- StringTag tag;
1911
+ auto tag = std::make_unique<StringTag>() ;
1924
1912
if (args.size () >= 2 && args[1 ].isString ()) {
1925
- tag = args[1 ].toStr ();
1913
+ * tag = args[1 ].toStr ();
1926
1914
}
1927
- res = NbtStringClass::pack (std::move (& tag));
1915
+ res = NbtStringClass::pack (std::move (tag));
1928
1916
break ;
1929
1917
}
1930
1918
case Tag::Type::ByteArray: {
1931
- ByteArrayTag tag;
1919
+ auto tag = std::make_unique<ByteArrayTag>() ;
1932
1920
if (args.size () >= 2 && args[1 ].isByteBuffer ()) {
1933
1921
Local<ByteBuffer> buf = args[1 ].asByteBuffer ();
1934
1922
for (char data : buf.describeUtf8 ()) {
1935
- tag. push_back (data);
1923
+ tag-> push_back (data);
1936
1924
}
1937
1925
}
1938
- res = NbtByteArrayClass::pack (std::move (& tag));
1926
+ res = NbtByteArrayClass::pack (std::move (tag));
1939
1927
break ;
1940
1928
}
1941
1929
case Tag::Type::List: {
1942
- ListTag tag;
1930
+ auto tag = std::make_unique<ListTag>() ;
1943
1931
if (args.size () >= 2 && args[1 ].isArray ()) {
1944
1932
Local<Array> arr = args[1 ].asArray ();
1945
- NbtListClassAddHelper (& tag, arr);
1933
+ NbtListClassAddHelper (tag. get () , arr);
1946
1934
}
1947
- res = NbtListClass::pack (std::move (& tag));
1935
+ res = NbtListClass::pack (std::move (tag));
1948
1936
break ;
1949
1937
}
1950
1938
case Tag::Type::Compound: {
1951
- CompoundTag tag;
1939
+ auto tag = std::make_unique<CompoundTag>() ;
1952
1940
if (args.size () >= 2 && args[1 ].isObject ()) {
1953
1941
Local<Object> obj = args[1 ].asObject ();
1954
- NbtCompoundClassAddHelper (& tag, obj);
1942
+ NbtCompoundClassAddHelper (tag. get () , obj);
1955
1943
}
1956
- res = NbtCompoundClass::pack (std::move (& tag));
1944
+ res = NbtCompoundClass::pack (std::move (tag));
1957
1945
break ;
1958
1946
}
1959
1947
case Tag::Type::End:
@@ -1972,7 +1960,7 @@ Local<Value> NbtStatic::parseSNBT(const Arguments& args) {
1972
1960
1973
1961
try {
1974
1962
auto tag = CompoundTag::fromSnbt (args[0 ].toStr ());
1975
- if (tag.has_value ()) return NbtCompoundClass::pack (std::move ( tag-> clone () ));
1963
+ if (tag.has_value ()) return NbtCompoundClass::pack (& tag. value ( ));
1976
1964
else return Local<Value>();
1977
1965
}
1978
1966
CATCH (" Fail in parseSNBT!" );
@@ -1985,7 +1973,7 @@ Local<Value> NbtStatic::parseBinaryNBT(const Arguments& args) {
1985
1973
try {
1986
1974
auto data = args[0 ].asByteBuffer ();
1987
1975
auto tag = CompoundTag::fromBinaryNbt (std::string_view ((char *)data.getRawBytes (), data.byteLength ()));
1988
- if (tag.has_value ()) return NbtCompoundClass::pack (std::move ( tag-> clone () ));
1976
+ if (tag.has_value ()) return NbtCompoundClass::pack (& tag. value ( ));
1989
1977
else return Local<Value>();
1990
1978
}
1991
1979
CATCH (" Fail in parseBinaryNBT!" );
@@ -2144,11 +2132,11 @@ Local<Value> Tag2Value(Tag* nbt, bool autoExpansion) {
2144
2132
break ;
2145
2133
}
2146
2134
case Tag::Type::List:
2147
- if (!autoExpansion) value = NbtListClass::pack (nbt->as_ptr <ListTag>(), true );
2135
+ if (!autoExpansion) value = NbtListClass::pack (nbt->as_ptr <ListTag>());
2148
2136
else value = Tag2Value_ListHelper (nbt->as_ptr <ListTag>(), autoExpansion);
2149
2137
break ;
2150
2138
case Tag::Type::Compound:
2151
- if (!autoExpansion) value = NbtCompoundClass::pack (nbt->as_ptr <CompoundTag>(), true );
2139
+ if (!autoExpansion) value = NbtCompoundClass::pack (nbt->as_ptr <CompoundTag>());
2152
2140
else value = Tag2Value_CompoundHelper (nbt->as_ptr <CompoundTag>(), autoExpansion);
2153
2141
break ;
2154
2142
case Tag::Type::End:
0 commit comments