mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Add the slightly faster sqlite3DbMallocRawNN(db,n) routine for the majority
cases where db is guaranteed to be not NULL. FossilOrigin-Name: 0a802e96ab06e2643834b83671fa8353da1a348d
This commit is contained in:
27
src/expr.c
27
src/expr.c
@@ -453,6 +453,7 @@ Expr *sqlite3ExprAlloc(
|
||||
int nExtra = 0;
|
||||
int iValue = 0;
|
||||
|
||||
assert( db!=0 );
|
||||
if( pToken ){
|
||||
if( op!=TK_INTEGER || pToken->z==0
|
||||
|| sqlite3GetInt32(pToken->z, &iValue)==0 ){
|
||||
@@ -460,7 +461,7 @@ Expr *sqlite3ExprAlloc(
|
||||
assert( iValue>=0 );
|
||||
}
|
||||
}
|
||||
pNew = sqlite3DbMallocRaw(db, sizeof(Expr)+nExtra);
|
||||
pNew = sqlite3DbMallocRawNN(db, sizeof(Expr)+nExtra);
|
||||
if( pNew ){
|
||||
memset(pNew, 0, sizeof(Expr));
|
||||
pNew->op = (u8)op;
|
||||
@@ -857,6 +858,7 @@ static int dupedExprSize(Expr *p, int flags){
|
||||
static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
|
||||
Expr *pNew = 0; /* Value to return */
|
||||
assert( flags==0 || flags==EXPRDUP_REDUCE );
|
||||
assert( db!=0 );
|
||||
if( p ){
|
||||
const int isReduced = (flags&EXPRDUP_REDUCE);
|
||||
u8 *zAlloc;
|
||||
@@ -869,7 +871,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
|
||||
zAlloc = *pzBuffer;
|
||||
staticFlag = EP_Static;
|
||||
}else{
|
||||
zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
|
||||
zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, flags));
|
||||
}
|
||||
pNew = (Expr *)zAlloc;
|
||||
|
||||
@@ -992,12 +994,13 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
|
||||
ExprList *pNew;
|
||||
struct ExprList_item *pItem, *pOldItem;
|
||||
int i;
|
||||
assert( db!=0 );
|
||||
if( p==0 ) return 0;
|
||||
pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
|
||||
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->nExpr = i = p->nExpr;
|
||||
if( (flags & EXPRDUP_REDUCE)==0 ) for(i=1; i<p->nExpr; i+=i){}
|
||||
pNew->a = pItem = sqlite3DbMallocRaw(db, i*sizeof(p->a[0]) );
|
||||
pNew->a = pItem = sqlite3DbMallocRawNN(db, i*sizeof(p->a[0]) );
|
||||
if( pItem==0 ){
|
||||
sqlite3DbFree(db, pNew);
|
||||
return 0;
|
||||
@@ -1028,9 +1031,10 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
|
||||
SrcList *pNew;
|
||||
int i;
|
||||
int nByte;
|
||||
assert( db!=0 );
|
||||
if( p==0 ) return 0;
|
||||
nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0);
|
||||
pNew = sqlite3DbMallocRaw(db, nByte );
|
||||
pNew = sqlite3DbMallocRawNN(db, nByte );
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->nSrc = pNew->nAlloc = p->nSrc;
|
||||
for(i=0; i<p->nSrc; i++){
|
||||
@@ -1067,11 +1071,12 @@ SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
|
||||
IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
|
||||
IdList *pNew;
|
||||
int i;
|
||||
assert( db!=0 );
|
||||
if( p==0 ) return 0;
|
||||
pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
|
||||
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->nId = p->nId;
|
||||
pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
|
||||
pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
|
||||
if( pNew->a==0 ){
|
||||
sqlite3DbFree(db, pNew);
|
||||
return 0;
|
||||
@@ -1089,8 +1094,9 @@ IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
|
||||
}
|
||||
Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
|
||||
Select *pNew, *pPrior;
|
||||
assert( db!=0 );
|
||||
if( p==0 ) return 0;
|
||||
pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
|
||||
pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
|
||||
if( pNew==0 ) return 0;
|
||||
pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
|
||||
pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
|
||||
@@ -1136,13 +1142,14 @@ ExprList *sqlite3ExprListAppend(
|
||||
Expr *pExpr /* Expression to be appended. Might be NULL */
|
||||
){
|
||||
sqlite3 *db = pParse->db;
|
||||
assert( db!=0 );
|
||||
if( pList==0 ){
|
||||
pList = sqlite3DbMallocRaw(db, sizeof(ExprList) );
|
||||
pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
|
||||
if( pList==0 ){
|
||||
goto no_mem;
|
||||
}
|
||||
pList->nExpr = 0;
|
||||
pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0]));
|
||||
pList->a = sqlite3DbMallocRawNN(db, sizeof(pList->a[0]));
|
||||
if( pList->a==0 ) goto no_mem;
|
||||
}else if( (pList->nExpr & (pList->nExpr-1))==0 ){
|
||||
struct ExprList_item *a;
|
||||
|
Reference in New Issue
Block a user