Skip to content

Commit 199bbf2

Browse files
author
maciejmakowski2003
committed
refactor: better approach
1 parent 4836915 commit 199bbf2

File tree

6 files changed

+8
-54
lines changed

6 files changed

+8
-54
lines changed

packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ AudioNodeHostObject::AudioNodeHostObject(const std::shared_ptr<AudioNode> &node)
1919
JSI_EXPORT_FUNCTION(AudioNodeHostObject, disconnect));
2020
}
2121

22-
// Explicitly define destructor here, as they to exist in order to act as a
23-
// "key function" for the audio classes - this allow for RTTI to work
24-
// properly across dynamic library boundaries (i.e. dynamic_cast that is used by
25-
// isHostObject method), android specific issue
26-
AudioNodeHostObject::~AudioNodeHostObject() = default;
27-
2822
JSI_PROPERTY_GETTER_IMPL(AudioNodeHostObject, numberOfInputs) {
2923
return {node_->getNumberOfInputs()};
3024
}

packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class AudioNode;
1414
class AudioNodeHostObject : public JsiHostObject {
1515
public:
1616
explicit AudioNodeHostObject(const std::shared_ptr<AudioNode> &node);
17-
~AudioNodeHostObject() override;
1817

1918
JSI_PROPERTY_GETTER_DECL(numberOfInputs);
2019
JSI_PROPERTY_GETTER_DECL(numberOfOutputs);

packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ BaseAudioContextHostObject::BaseAudioContextHostObject(
6262
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createWaveShaper));
6363
}
6464

65-
// Explicitly define destructors here, as they to exist in order to act as a
66-
// "key function" for the audio classes - this allow for RTTI to work
67-
// properly across dynamic library boundaries (i.e. dynamic_cast that is used by
68-
// isHostObject method), android specific issue
69-
BaseAudioContextHostObject::~BaseAudioContextHostObject() = default;
70-
7165
JSI_PROPERTY_GETTER_IMPL(BaseAudioContextHostObject, destination) {
7266
auto destination = std::make_shared<AudioDestinationNodeHostObject>(context_->getDestination());
7367
return jsi::Object::createFromHostObject(runtime, destination);

packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class BaseAudioContextHostObject : public JsiHostObject {
2121
jsi::Runtime *runtime,
2222
const std::shared_ptr<react::CallInvoker> &callInvoker);
2323

24-
~BaseAudioContextHostObject() override;
25-
2624
JSI_PROPERTY_GETTER_DECL(destination);
2725
JSI_PROPERTY_GETTER_DECL(state);
2826
JSI_PROPERTY_GETTER_DECL(sampleRate);

packages/react-native-audio-api/common/cpp/audioapi/jsi/JsiHostObject.cpp

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
#include <utility>
66
#include <vector>
77

8-
// set this value to 1 in order to debug the construction/destruction
9-
#define JSI_DEBUG_ALLOCATIONS 0
10-
118
namespace audioapi {
129

13-
#if JSI_DEBUG_ALLOCATIONS
14-
int objCounter = 0;
15-
std::vector<JsiHostObject *> objects;
16-
#endif
17-
1810
JsiHostObject::JsiHostObject() {
1911
getters_ = std::make_unique<
2012
std::unordered_map<std::string, jsi::Value (JsiHostObject::*)(jsi::Runtime &)>>();
@@ -25,52 +17,24 @@ JsiHostObject::JsiHostObject() {
2517
setters_ = std::make_unique<std::unordered_map<
2618
std::string,
2719
void (JsiHostObject::*)(jsi::Runtime &, const jsi::Value &)>>();
28-
29-
#if JSI_DEBUG_ALLOCATIONS
30-
objects.push_back(this);
31-
objCounter++;
32-
#endif
3320
}
3421

3522
JsiHostObject::JsiHostObject(JsiHostObject &&other) noexcept
3623
: getters_(std::move(other.getters_)),
3724
functions_(std::move(other.functions_)),
38-
setters_(std::move(other.setters_)) {
39-
#if JSI_DEBUG_ALLOCATIONS
40-
auto it = std::find(objects.begin(), objects.end(), &other);
41-
if (it != objects.end()) {
42-
objects.erase(it);
43-
}
44-
objects.push_back(this);
45-
#endif
46-
}
25+
setters_(std::move(other.setters_)) {}
4726

4827
JsiHostObject &JsiHostObject::operator=(JsiHostObject &&other) noexcept {
4928
if (this != &other) {
5029
getters_ = std::move(other.getters_);
5130
functions_ = std::move(other.functions_);
5231
setters_ = std::move(other.setters_);
53-
54-
#if JSI_DEBUG_ALLOCATIONS
55-
auto it = std::find(objects.begin(), objects.end(), &other);
56-
if (it != objects.end()) {
57-
objects.erase(it);
58-
}
59-
objects.push_back(this);
60-
#endif
6132
}
33+
6234
return *this;
6335
}
6436

65-
JsiHostObject::~JsiHostObject() {
66-
#if JSI_DEBUG_ALLOCATIONS
67-
auto it = std::find(objects.begin(), objects.end(), this);
68-
if (it != objects.end()) {
69-
objects.erase(it);
70-
objCounter--;
71-
}
72-
#endif
73-
}
37+
JsiHostObject::~JsiHostObject() = default;
7438

7539
std::vector<jsi::PropNameID> JsiHostObject::getPropertyNames(jsi::Runtime &rt) {
7640
std::vector<jsi::PropNameID> propertyNames;

packages/react-native-audio-api/common/cpp/audioapi/jsi/JsiHostObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class JsiHostObject : public jsi::HostObject {
4848
JsiHostObject &operator=(const JsiHostObject &) = delete;
4949
JsiHostObject(JsiHostObject &&) noexcept;
5050
JsiHostObject &operator=(JsiHostObject &&other) noexcept;
51+
52+
// Explicitly define destructor here, as they to exist in order to act as a
53+
// "key function" for the audio classes - this allow for RTTI to work
54+
// properly across dynamic library boundaries (i.e. dynamic_cast that is used by
55+
// isHostObject method), android specific issue
5156
~JsiHostObject() override;
5257

5358
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;

0 commit comments

Comments
 (0)