Ticket #2127 - Performance and style improvements in scriptinterface.
No real behavior changes, only code maintenance. Fixed signed/unsigned mismatch in EntityMap.h This was SVN commit r13865.
This commit is contained in:
parent
97912dd545
commit
5d9b2b95b0
@ -45,6 +45,7 @@ Will Dull [livingaftermidnight]
|
||||
# Other contributors:
|
||||
|
||||
André Puel
|
||||
Jonas Platte <jonasplatte@myopera.com>
|
||||
Lars Kemmann
|
||||
Nick Owens <digitalseraphim@gmail.com>
|
||||
Quentin Pradet <quentin.pradet@gmail.com>
|
||||
|
@ -33,7 +33,7 @@ const char* CDebuggingServer::header400 =
|
||||
void CDebuggingServer::GetAllCallstacks(std::stringstream& response)
|
||||
{
|
||||
CScopeLock lock(m_Mutex);
|
||||
response.str("");
|
||||
response.str(std::string());
|
||||
std::stringstream stream;
|
||||
uint nbrCallstacksWritten = 0;
|
||||
std::list<CThreadDebugger*>::iterator itr;
|
||||
@ -44,15 +44,13 @@ void CDebuggingServer::GetAllCallstacks(std::stringstream& response)
|
||||
{
|
||||
if ((*itr)->GetIsInBreak())
|
||||
{
|
||||
stream.str("");
|
||||
std::string str = stream.str();
|
||||
stream.str(std::string());
|
||||
(*itr)->GetCallstack(stream);
|
||||
str = stream.str();
|
||||
if (stream.str() != "")
|
||||
if ((int)stream.tellp() != 0)
|
||||
{
|
||||
if (nbrCallstacksWritten != 0)
|
||||
response << ",";
|
||||
response << "{" << "\"ThreadDebuggerID\" : " << (*itr)->GetID() << ", \"CallStack\" : " << stream.str() << "}";
|
||||
response << "{" << "\"ThreadDebuggerID\" : " << (*itr)->GetID() << ", \"CallStack\" : " << stream << "}";
|
||||
nbrCallstacksWritten++;
|
||||
}
|
||||
|
||||
@ -65,17 +63,17 @@ void CDebuggingServer::GetAllCallstacks(std::stringstream& response)
|
||||
void CDebuggingServer::GetStackFrameData(std::stringstream& response, uint nestingLevel, uint threadDebuggerID, STACK_INFO stackInfoKind)
|
||||
{
|
||||
CScopeLock lock(m_Mutex);
|
||||
response.str("");
|
||||
response.str(std::string());
|
||||
std::stringstream stream;
|
||||
std::list<CThreadDebugger*>::iterator itr;
|
||||
for (itr = m_ThreadDebuggers.begin(); itr != m_ThreadDebuggers.end(); ++itr)
|
||||
{
|
||||
if ( (*itr)->GetID() == threadDebuggerID && (*itr)->GetIsInBreak())
|
||||
if ((*itr)->GetID() == threadDebuggerID && (*itr)->GetIsInBreak())
|
||||
{
|
||||
(*itr)->GetStackFrameData(stream, nestingLevel, stackInfoKind);
|
||||
if (stream.str() != "")
|
||||
if ((int)stream.tellp() != 0)
|
||||
{
|
||||
response << stream.str();
|
||||
response << stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,7 +112,7 @@ bool CDebuggingServer::SetNextDbgCmd(uint threadDebuggerID, DBGCMD dbgCmd)
|
||||
std::list<CThreadDebugger*>::iterator itr;
|
||||
for (itr = m_ThreadDebuggers.begin(); itr != m_ThreadDebuggers.end(); ++itr)
|
||||
{
|
||||
if ( (*itr)->GetID() == threadDebuggerID || threadDebuggerID == 0)
|
||||
if ((*itr)->GetID() == threadDebuggerID || threadDebuggerID == 0)
|
||||
{
|
||||
if (DBG_CMD_NONE == (*itr)->GetNextDbgCmd() && (*itr)->GetIsInBreak())
|
||||
{
|
||||
@ -188,7 +186,7 @@ void CDebuggingServer::EnumVfsJSFiles(std::stringstream& response)
|
||||
{
|
||||
VfsPath path = L"";
|
||||
VfsPaths pathnames;
|
||||
response.str("");
|
||||
response.str(std::string());
|
||||
|
||||
std::vector<std::string> templates;
|
||||
vfs::ForEachFile(g_VFS, "", AddFileResponse, (uintptr_t)&templates, L"*.js", vfs::DIR_RECURSIVE);
|
||||
@ -438,8 +436,8 @@ bool CDebuggingServer::GetWebArgs(struct mg_connection *conn, const struct mg_re
|
||||
int len = mg_get_var(request_info->query_string, strlen(request_info->query_string), argName.c_str(), buf, ARRAY_SIZE(buf));
|
||||
if (len < 0)
|
||||
{
|
||||
mg_printf(conn, "%s (no '%s')", header400, argName.c_str());
|
||||
return false;
|
||||
mg_printf(conn, "%s (no '%s')", header400, argName.c_str());
|
||||
return false;
|
||||
}
|
||||
arg = atoi(buf);
|
||||
return true;
|
||||
@ -492,7 +490,7 @@ void CDebuggingServer::UnRegisterScriptinterface(ScriptInterface* pScriptInterfa
|
||||
void CDebuggingServer::GetThreadDebuggerStatus(std::stringstream& response)
|
||||
{
|
||||
CScopeLock lock(m_Mutex);
|
||||
response.str("");
|
||||
response.str(std::string());
|
||||
std::list<CThreadDebugger*>::iterator itr;
|
||||
|
||||
response << "[";
|
||||
@ -529,11 +527,10 @@ void CDebuggingServer::ToggleBreakPoint(std::string filename, uint line)
|
||||
// If the breakpoint isn't handled yet search the breakpoints registered in this class
|
||||
std::list<CBreakPoint>* pBreakPoints = NULL;
|
||||
double breakPointsLockID = AquireBreakPointAccess(&pBreakPoints);
|
||||
std::list<CBreakPoint>::iterator itr;
|
||||
|
||||
// If set, delete
|
||||
bool deleted = false;
|
||||
for (itr = pBreakPoints->begin(); itr != pBreakPoints->end(); ++itr)
|
||||
for (std::list<CBreakPoint>::iterator itr = pBreakPoints->begin(); itr != pBreakPoints->end(); ++itr)
|
||||
{
|
||||
if ((*itr).m_Filename == filename && (*itr).m_UserLine == line)
|
||||
{
|
||||
@ -560,7 +557,7 @@ double CDebuggingServer::AquireBreakPointAccess(std::list<CBreakPoint>** breakPo
|
||||
{
|
||||
int ret;
|
||||
ret = SDL_SemWait(m_BreakPointsSem);
|
||||
ENSURE(0 == ret);
|
||||
ENSURE(ret == 0);
|
||||
(*breakPoints) = &m_BreakPoints;
|
||||
m_BreakPointsLockID = timer_Time();
|
||||
return m_BreakPointsLockID;
|
||||
|
@ -1092,7 +1092,7 @@ std::string ScriptInterface::StringifyJSON(jsval obj, bool indent)
|
||||
JS_ClearPendingException(m->m_cx);
|
||||
LOGERROR(L"StringifyJSON failed");
|
||||
JS_ClearPendingException(m->m_cx);
|
||||
return "";
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return str.stream.str();
|
||||
|
@ -168,10 +168,13 @@ public:
|
||||
uint m_ID;
|
||||
};
|
||||
|
||||
ThreadDebugger_impl::ThreadDebugger_impl() :
|
||||
m_NextDbgCmd(DBG_CMD_NONE), m_IsInBreak(false), m_pLastBreakFrame(new JSStackFrame*)
|
||||
{
|
||||
}
|
||||
ThreadDebugger_impl::ThreadDebugger_impl()
|
||||
: m_NextDbgCmd(DBG_CMD_NONE)
|
||||
, m_pScriptInterface(NULL)
|
||||
, m_pDebuggingServer(NULL)
|
||||
, m_pLastBreakFrame(new JSStackFrame*)
|
||||
, m_IsInBreak(false)
|
||||
{ }
|
||||
|
||||
ThreadDebugger_impl::~ThreadDebugger_impl()
|
||||
{
|
||||
@ -188,11 +191,10 @@ void CThreadDebugger::ClearTrapsToRemove()
|
||||
{
|
||||
if ((*itr)->m_ToRemove)
|
||||
{
|
||||
ClearTrap((*itr));
|
||||
// Remove the breakpoint
|
||||
delete (*itr);
|
||||
itr = m->m_ActiveBreakPoints.erase(itr);
|
||||
|
||||
ClearTrap((*itr));
|
||||
// Remove the breakpoint
|
||||
delete (*itr);
|
||||
itr = m->m_ActiveBreakPoints.erase(itr);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
@ -527,7 +529,7 @@ JSTrapStatus CThreadDebugger::BreakHandler(JSContext* cx, JSScript* script, jsby
|
||||
SetAllNewTraps();
|
||||
SetNextDbgCmd(DBG_CMD_NONE);
|
||||
SetIsInBreak(false);
|
||||
SetBreakFileName("");
|
||||
SetBreakFileName(std::string());
|
||||
|
||||
// All saved stack data becomes invalid
|
||||
{
|
||||
@ -542,7 +544,7 @@ void CThreadDebugger::NewScriptHook(JSContext* cx, const char* filename, unsigne
|
||||
{
|
||||
uint scriptExtent = JS_GetScriptLineExtent (cx, script);
|
||||
std::string stringFileName(filename);
|
||||
if (stringFileName == "")
|
||||
if (stringFileName.empty())
|
||||
return;
|
||||
|
||||
for (uint line = lineno; line < scriptExtent + lineno; ++line)
|
||||
@ -648,7 +650,6 @@ void CThreadDebugger::SaveCallstack()
|
||||
|
||||
JSStackFrame *fp;
|
||||
JSStackFrame *iter = 0;
|
||||
std::string functionName;
|
||||
jsint counter = 0;
|
||||
|
||||
JSObject* jsArray;
|
||||
@ -676,7 +677,7 @@ void CThreadDebugger::SaveCallstack()
|
||||
counter++;
|
||||
}
|
||||
|
||||
m->m_Callstack = "";
|
||||
m->m_Callstack.clear();
|
||||
m->m_Callstack = m->m_pScriptInterface->StringifyJSON(OBJECT_TO_JSVAL(jsArray), false).c_str();
|
||||
}
|
||||
|
||||
@ -699,7 +700,7 @@ void CThreadDebugger::GetStackFrameData(std::stringstream& response, uint nestin
|
||||
|
||||
CScopeLock lock(m->m_Mutex);
|
||||
{
|
||||
response.str("");
|
||||
response.str(std::string());
|
||||
response << m->m_StackFrameData[stackInfoKind][nestingLevel];
|
||||
}
|
||||
}
|
||||
@ -718,7 +719,6 @@ void CThreadDebugger::SaveStackFrameData(STACK_INFO stackInfo, uint nestingLevel
|
||||
ENSURE(GetIsInBreak());
|
||||
|
||||
CScopeLock lock(m->m_Mutex);
|
||||
JSStackFrame *fp;
|
||||
JSStackFrame *iter = 0;
|
||||
uint counter = 0;
|
||||
jsval val;
|
||||
@ -731,7 +731,7 @@ void CThreadDebugger::SaveStackFrameData(STACK_INFO stackInfo, uint nestingLevel
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = JS_FrameIterator(m->m_pScriptInterface->GetContext(), &iter);
|
||||
JSStackFrame *fp = JS_FrameIterator(m->m_pScriptInterface->GetContext(), &iter);
|
||||
while (fp)
|
||||
{
|
||||
if (counter == nestingLevel)
|
||||
@ -766,20 +766,20 @@ void CThreadDebugger::SaveStackFrameData(STACK_INFO stackInfo, uint nestingLevel
|
||||
* Unfortunately this seems to require writing (or embedding) a new serializer to JSON or something similar.
|
||||
*
|
||||
* Some things about the implementation which aren't optimal:
|
||||
* 1. It uses globabl variables (they are limited to a namespace though)
|
||||
* 1. It uses global variables (they are limited to a namespace though).
|
||||
* 2. It has to work around a bug in Spidermonkey.
|
||||
* 3. It copies code from CScriptInterface. I did this to separate it cleanly because the debugger should not affect
|
||||
* the rest of the game and because this part of code should be replaced anyway in the future.
|
||||
*/
|
||||
|
||||
namespace CyclicRefWorkaround
|
||||
{
|
||||
namespace CyclicRefWorkaround
|
||||
{
|
||||
std::set<JSObject*> g_ProcessedObjects;
|
||||
jsval g_LastKey;
|
||||
jsval g_LastValue;
|
||||
bool g_RecursionDetectedInPrevReplacer = false;
|
||||
uint g_countSameKeys = 0;
|
||||
|
||||
|
||||
struct Stringifier
|
||||
{
|
||||
static JSBool callback(const jschar* buf, uint32 len, void* data)
|
||||
@ -794,7 +794,7 @@ void CThreadDebugger::SaveStackFrameData(STACK_INFO stackInfo, uint nestingLevel
|
||||
|
||||
std::stringstream stream;
|
||||
};
|
||||
|
||||
|
||||
JSBool replacer(JSContext* cx, uintN UNUSED(argc), jsval* vp)
|
||||
{
|
||||
jsval value = JS_ARGV(cx, vp)[1];
|
||||
@ -830,8 +830,8 @@ void CThreadDebugger::SaveStackFrameData(STACK_INFO stackInfo, uint nestingLevel
|
||||
JS_SET_RVAL(cx, vp, JS_ARGV(cx, vp)[1]);
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string CThreadDebugger::StringifyCyclicJSON(jsval obj, bool indent)
|
||||
{
|
||||
CyclicRefWorkaround::Stringifier str;
|
||||
@ -861,14 +861,14 @@ std::string CThreadDebugger::StringifyCyclicJSON(jsval obj, bool indent)
|
||||
|
||||
}
|
||||
JS_ClearPendingException(m->m_pScriptInterface->GetContext());
|
||||
return "";
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return str.stream.str();
|
||||
}
|
||||
|
||||
|
||||
bool CThreadDebugger::CompareScriptInterfacePtr(ScriptInterface* pScriptInterface)
|
||||
bool CThreadDebugger::CompareScriptInterfacePtr(ScriptInterface* pScriptInterface) const
|
||||
{
|
||||
return (pScriptInterface == m->m_pScriptInterface);
|
||||
}
|
||||
|
@ -27,7 +27,8 @@
|
||||
class CBreakPoint
|
||||
{
|
||||
public:
|
||||
CBreakPoint() { m_UserLine = 0; m_Filename = ""; }
|
||||
CBreakPoint() : m_UserLine(0) { }
|
||||
|
||||
uint m_UserLine;
|
||||
std::string m_Filename;
|
||||
};
|
||||
@ -36,26 +37,20 @@ public:
|
||||
class CActiveBreakPoint : public CBreakPoint
|
||||
{
|
||||
public:
|
||||
CActiveBreakPoint() :
|
||||
CBreakPoint()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
CActiveBreakPoint()
|
||||
: m_ActualLine(m_UserLine)
|
||||
, m_Script(NULL)
|
||||
, m_Pc(NULL)
|
||||
, m_ToRemove(false)
|
||||
{ }
|
||||
|
||||
CActiveBreakPoint(CBreakPoint breakPoint)
|
||||
{
|
||||
m_Filename = breakPoint.m_Filename;
|
||||
m_UserLine = breakPoint.m_UserLine;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
m_ToRemove = false;
|
||||
m_Script = NULL;
|
||||
m_Pc = NULL;
|
||||
m_ActualLine = m_UserLine;
|
||||
}
|
||||
: CBreakPoint(breakPoint) // using default copy constructor
|
||||
, m_ActualLine(m_UserLine)
|
||||
, m_Script(NULL)
|
||||
, m_Pc(NULL)
|
||||
, m_ToRemove(false)
|
||||
{ }
|
||||
|
||||
uint m_ActualLine;
|
||||
JSScript* m_Script;
|
||||
@ -151,7 +146,7 @@ public:
|
||||
/** @brief Compares the object's associated scriptinterface with the pointer passed as parameter.
|
||||
* @return true if equal
|
||||
*/
|
||||
bool CompareScriptInterfacePtr(ScriptInterface* pScriptInterface);
|
||||
bool CompareScriptInterfacePtr(ScriptInterface* pScriptInterface) const;
|
||||
|
||||
// Getter/Setters for members that need to be threadsafe
|
||||
std::string GetBreakFileName();
|
||||
|
@ -126,7 +126,7 @@ public:
|
||||
{
|
||||
if (key >= m_BufferCapacity) // do we need to resize buffer?
|
||||
{
|
||||
int newCapacity = m_BufferCapacity + 4096;
|
||||
size_t newCapacity = m_BufferCapacity + 4096;
|
||||
while (key >= newCapacity) newCapacity += 4096;
|
||||
// always allocate +1 behind the scenes, because end() must have a 0xFFFFFFFF key
|
||||
value_type* mem = (value_type*)realloc(m_Buffer, sizeof(value_type) * (newCapacity + 1));
|
||||
|
Loading…
Reference in New Issue
Block a user