Bug 584298. Do a bit less work in ReadableToJSVal on the fast path. r=jst

This commit is contained in:
Boris Zbarsky 2010-08-06 20:46:52 -04:00
parent 78ca39176b
commit 0081737f57
5 changed files with 22 additions and 26 deletions

View File

@ -330,9 +330,12 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
break;
if(!p->IsVoid()) {
jsval str = XPCStringConvert::ReadableToJSVal(cx, *p);
nsStringBuffer* buf;
jsval str = XPCStringConvert::ReadableToJSVal(cx, *p, &buf);
if(JSVAL_IS_NULL(str))
return JS_FALSE;
if(buf)
buf->AddRef();
*d = str;
}

View File

@ -113,6 +113,7 @@
#include "nsBaseHashtable.h"
#include "nsHashKeys.h"
#include "nsWrapperCache.h"
#include "nsStringBuffer.h"
#include "nsIXPCScriptNotify.h" // used to notify: ScriptEvaluated
@ -3226,9 +3227,11 @@ class XPCStringConvert
{
public:
// If the string shares the readable's buffer, that buffer will
// get assigned to *sharedBuffer. Otherwise null will be
// assigned.
static jsval ReadableToJSVal(JSContext *cx, const nsAString &readable,
PRBool dontAddrefShared = PR_FALSE,
PRBool* sharedBuffer = nsnull);
nsStringBuffer** sharedBuffer);
static XPCReadableJSStringWrapper *JSStringToReadable(XPCCallContext& ccx,
JSString *str);

View File

@ -1071,13 +1071,12 @@ xpc_qsStringToJsval(JSContext *cx, nsString &str, jsval *rval)
return JS_TRUE;
}
PRBool isShared = PR_FALSE;
jsval jsstr =
XPCStringConvert::ReadableToJSVal(cx, str, PR_TRUE, &isShared);
nsStringBuffer* sharedBuffer;
jsval jsstr = XPCStringConvert::ReadableToJSVal(cx, str, &sharedBuffer);
if (JSVAL_IS_NULL(jsstr))
return JS_FALSE;
*rval = jsstr;
if (isShared)
if (sharedBuffer)
{
// The string was shared but ReadableToJSVal didn't addref it.
// Move the ownership from str to jsstr.
@ -1096,13 +1095,12 @@ xpc_qsStringToJsstring(JSContext *cx, nsString &str, JSString **rval)
return JS_TRUE;
}
PRBool isShared = PR_FALSE;
jsval jsstr =
XPCStringConvert::ReadableToJSVal(cx, str, PR_TRUE, &isShared);
nsStringBuffer* sharedBuffer;
jsval jsstr = XPCStringConvert::ReadableToJSVal(cx, str, &sharedBuffer);
if(JSVAL_IS_NULL(jsstr))
return JS_FALSE;
*rval = JSVAL_TO_STRING(jsstr);
if (isShared)
if (sharedBuffer)
{
// The string was shared but ReadableToJSVal didn't addref it.
// Move the ownership from str to jsstr.

View File

@ -78,14 +78,10 @@ XPCStringConvert::ShutdownDOMStringFinalizer()
jsval
XPCStringConvert::ReadableToJSVal(JSContext *cx,
const nsAString &readable,
PRBool dontAddrefShared,
PRBool* sharedBuffer)
nsStringBuffer** sharedBuffer)
{
JSString *str;
if (sharedBuffer)
{
*sharedBuffer = PR_FALSE;
}
*sharedBuffer = nsnull;
PRUint32 length = readable.Length();
@ -114,14 +110,7 @@ XPCStringConvert::ReadableToJSVal(JSContext *cx,
if (str)
{
if (sharedBuffer)
{
*sharedBuffer = PR_TRUE;
}
if (!dontAddrefShared)
{
buf->AddRef();
}
*sharedBuffer = buf;
}
}
else

View File

@ -620,9 +620,12 @@ nsXPCWrappedJS::GetProperty(const nsAString & name, nsIVariant **_retval)
if(!ccx.IsValid())
return NS_ERROR_UNEXPECTED;
jsval jsstr = XPCStringConvert::ReadableToJSVal(ccx, name);
nsStringBuffer* buf;
jsval jsstr = XPCStringConvert::ReadableToJSVal(ccx, name, &buf);
if(JSVAL_IS_NULL(jsstr))
return NS_ERROR_OUT_OF_MEMORY;
if(buf)
buf->AddRef();
return nsXPCWrappedJSClass::
GetNamedPropertyAsVariant(ccx, mJSObj, jsstr, _retval);