Skip to content

Commit

Permalink
Merge pull request #2124 from avancinirodrigo/master
Browse files Browse the repository at this point in the history
Fixing problem with performance after change C++ objects
  • Loading branch information
pedro-andrade-inpe authored Jan 25, 2018
2 parents d3b241f + 6992823 commit 1af8f61
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 29 deletions.
1 change: 0 additions & 1 deletion inttest/core/LuaApiMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class LuaApiMock : public terrame::lua::LuaApi
MOCK_METHOD1(getTopIndex, int(lua_State* L));
MOCK_METHOD2(nextAt, int(lua_State* L, int index));
MOCK_METHOD2(getTypeAt, int(lua_State* L, int index));
MOCK_METHOD0(getRefNilValue, int());

MOCK_METHOD2(isStringAt, bool(lua_State* L, int index));
MOCK_METHOD2(isNumberAt, bool(lua_State* L, int index));
Expand Down
14 changes: 0 additions & 14 deletions inttest/core/LuaCellTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ TEST_F(LuaCellTest, Constructor)
{
LuaApiMock* luaApiMock = new LuaApiMock();
terrame::lua::LuaSystem::getInstance().setLuaApi(luaApiMock);

EXPECT_CALL(*luaApiMock, getRefNilValue())
.Times(testing::AnyNumber())
.WillRepeatedly(testing::Return(-1));

luaCell* lc = new luaCell(L);

delete luaApiMock;
Expand All @@ -76,11 +71,6 @@ TEST_F(LuaCellTest, SetAndGetId)
{
LuaApiMock* luaApiMock = new LuaApiMock();
terrame::lua::LuaSystem::getInstance().setLuaApi(luaApiMock);

EXPECT_CALL(*luaApiMock, getRefNilValue())
.Times(testing::AnyNumber())
.WillRepeatedly(testing::Return(-1));

luaCell* lc = new luaCell(L);

EXPECT_CALL(*luaApiMock, getStringAtTop(testing::_))
Expand All @@ -101,10 +91,6 @@ TEST_F(LuaCellTest, CreateObserverAndKill)
LuaBindingMock<luaCell>* bindMock = new LuaBindingMock<luaCell>();
terrame::lua::LuaBindingDelegate<luaCell>::getInstance().setBinding(bindMock);

EXPECT_CALL(*luaApiMock, getRefNilValue())
.Times(testing::AnyNumber())
.WillRepeatedly(testing::Return(-1));

luaCell* lc = new luaCell(L);

EXPECT_CALL(*luaApiMock, getStringAtTop(testing::_))
Expand Down
1 change: 0 additions & 1 deletion src/core/LuaApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ namespace terrame
virtual int getTopIndex(lua_State* L) = 0;
virtual int nextAt(lua_State* L, int index) = 0;
virtual int getTypeAt(lua_State* L, int index) = 0;
virtual int getRefNilValue() = 0;

virtual bool isStringAt(lua_State* L, int index) = 0;
virtual bool isNumberAt(lua_State* L, int index) = 0;
Expand Down
5 changes: 0 additions & 5 deletions src/core/LuaFacade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ int terrame::lua::LuaFacade::getTypeAt(lua_State* L, int index)
return lua_type(L, index);
}

int terrame::lua::LuaFacade::getRefNilValue()
{
return LUA_REFNIL;
}

bool terrame::lua::LuaFacade::isStringAt(lua_State* L, int index)
{
return lua_type(L, index) == getStringType();
Expand Down
1 change: 0 additions & 1 deletion src/core/LuaFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace terrame
int getTopIndex(lua_State* L);
int nextAt(lua_State* L, int index);
int getTypeAt(lua_State* L, int index);
int getRefNilValue();

bool isStringAt(lua_State* L, int index);
bool isNumberAt(lua_State* L, int index);
Expand Down
12 changes: 5 additions & 7 deletions src/core/reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,10 @@ template <class T>
class Reference
{
public:
Reference()
{
m_ref = terrame::lua::LuaSystem::getInstance().getLuaApi()->getRefNilValue();
}

/// Sets the reference for the Lua object using the cObj pointer.
int setReference(lua_State *L)
{
if (m_ref == terrame::lua::LuaSystem::getInstance().getLuaApi()->getRefNilValue())
if (m_ref == LUA_REFNIL)
{
m_ref = terrame::lua::LuaSystem::getInstance().getLuaApi()->createWeakTable(L);
}
Expand All @@ -63,7 +58,10 @@ class Reference

private:
// Index for the table holding the objects on the Lua Registry
int m_ref;
static int m_ref;
};

template <typename T>
int Reference<T>::m_ref = LUA_REFNIL;

#endif // REFFERENCE_H

0 comments on commit 1af8f61

Please sign in to comment.