Skip to content

Commit

Permalink
Use COPY_LIST_ENTRIES in method installation
Browse files Browse the repository at this point in the history
This optimization avoids creating a temporary list object
  • Loading branch information
stevelinton authored and fingolfin committed Sep 4, 2018
1 parent 7794064 commit a3f05db
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lib/oper1.g
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ BIND_GLOBAL( "INSTALL_METHOD_FLAGS",
fi;
# push the other functions back
if not REREADING or not replace then
methods{[narg+BASE_SIZE_METHODS_OPER_ENTRY+i+1..narg+BASE_SIZE_METHODS_OPER_ENTRY+LEN_LIST(methods)]}
:= methods{[i+1..LEN_LIST(methods)]};
COPY_LIST_ENTRIES(methods, i+1, 1, methods, narg+BASE_SIZE_METHODS_OPER_ENTRY+i+1,1,
LEN_LIST(methods)-i);
fi;

# install the new method
Expand Down
52 changes: 32 additions & 20 deletions src/c_oper1.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef AVOID_PRECOMPILED
/* C file produced by GAC */
#include "compiled.h"
#define FILE_CRC "32938550"
#define FILE_CRC "70528668"

/* global variables used in handlers */
static GVar G_REREADING;
Expand Down Expand Up @@ -82,6 +82,8 @@ static GVar G_LEN__LIST;
static Obj GF_LEN__LIST;
static GVar G_APPEND__LIST__INTR;
static Obj GF_APPEND__LIST__INTR;
static GVar G_COPY__LIST__ENTRIES;
static Obj GF_COPY__LIST__ENTRIES;
static GVar G_CONV__STRING;
static Obj GF_CONV__STRING;
static GVar G_Print;
Expand Down Expand Up @@ -923,23 +925,31 @@ static Obj HdlrFunc3 (
}
if ( t_1 ) {

/* methods{[ narg + 5 + i + 1 .. narg + 5 + LEN_LIST( methods ) ]} := methods{[ i + 1 .. LEN_LIST( methods ) ]}; */
C_SUM_FIA( t_4, l_narg, INTOBJ_INT(5) )
C_SUM_FIA( t_3, t_4, l_i )
C_SUM_FIA( t_2, t_3, INTOBJ_INT(1) )
C_SUM_FIA( t_4, l_narg, INTOBJ_INT(5) )
t_6 = GF_LEN__LIST;
t_5 = CALL_1ARGS( t_6, l_methods );
CHECK_FUNC_RESULT( t_5 )
C_SUM_FIA( t_3, t_4, t_5 )
t_1 = Range2Check( t_2, t_3 );
C_SUM_FIA( t_4, l_i, INTOBJ_INT(1) )
t_6 = GF_LEN__LIST;
t_5 = CALL_1ARGS( t_6, l_methods );
CHECK_FUNC_RESULT( t_5 )
t_3 = Range2Check( t_4, t_5 );
t_2 = ElmsListCheck( l_methods, t_3 );
AsssListCheck( l_methods, t_1, t_2 );
/* COPY_LIST_ENTRIES( methods, i + 1, 1, methods, narg + 5 + i + 1, 1, LEN_LIST( methods ) - i ); */
t_1 = GF_COPY__LIST__ENTRIES;
t_2 = NEW_PLIST( T_PLIST, 7 );
SET_LEN_PLIST( t_2, 7 );
SET_ELM_PLIST( t_2, 1, l_methods );
CHANGED_BAG( t_2 );
C_SUM_FIA( t_3, l_i, INTOBJ_INT(1) )
SET_ELM_PLIST( t_2, 2, t_3 );
CHANGED_BAG( t_2 );
SET_ELM_PLIST( t_2, 3, INTOBJ_INT(1) );
SET_ELM_PLIST( t_2, 4, l_methods );
CHANGED_BAG( t_2 );
C_SUM_FIA( t_5, l_narg, INTOBJ_INT(5) )
C_SUM_FIA( t_4, t_5, l_i )
C_SUM_FIA( t_3, t_4, INTOBJ_INT(1) )
SET_ELM_PLIST( t_2, 5, t_3 );
CHANGED_BAG( t_2 );
SET_ELM_PLIST( t_2, 6, INTOBJ_INT(1) );
t_5 = GF_LEN__LIST;
t_4 = CALL_1ARGS( t_5, l_methods );
CHECK_FUNC_RESULT( t_4 )
C_DIFF_FIA( t_3, t_4, l_i )
SET_ELM_PLIST( t_2, 7, t_3 );
CHANGED_BAG( t_2 );
CALL_XARGS( t_1, t_2 );

}
/* fi */
Expand Down Expand Up @@ -4082,7 +4092,7 @@ static Obj HdlrFunc1 (
od;
fi;
if not REREADING or not replace then
methods{[ narg + 5 + i + 1 .. narg + 5 + LEN_LIST( methods ) ]} := methods{[ i + 1 .. LEN_LIST( methods ) ]};
COPY_LIST_ENTRIES( methods, i + 1, 1, methods, narg + 5 + i + 1, 1, LEN_LIST( methods ) - i );
fi;
if rel = true then
methods[i + 1] := RETURN_TRUE;
Expand Down Expand Up @@ -4650,6 +4660,7 @@ static Int PostRestore ( StructInitInfo * module )
G_RETURN__FALSE = GVarName( "RETURN_FALSE" );
G_LEN__LIST = GVarName( "LEN_LIST" );
G_APPEND__LIST__INTR = GVarName( "APPEND_LIST_INTR" );
G_COPY__LIST__ENTRIES = GVarName( "COPY_LIST_ENTRIES" );
G_CONV__STRING = GVarName( "CONV_STRING" );
G_Print = GVarName( "Print" );
G_ViewObj = GVarName( "ViewObj" );
Expand Down Expand Up @@ -4766,6 +4777,7 @@ static Int InitKernel ( StructInitInfo * module )
InitCopyGVar( "RETURN_FALSE", &GC_RETURN__FALSE );
InitFopyGVar( "LEN_LIST", &GF_LEN__LIST );
InitFopyGVar( "APPEND_LIST_INTR", &GF_APPEND__LIST__INTR );
InitFopyGVar( "COPY_LIST_ENTRIES", &GF_COPY__LIST__ENTRIES );
InitFopyGVar( "CONV_STRING", &GF_CONV__STRING );
InitFopyGVar( "Print", &GF_Print );
InitCopyGVar( "ViewObj", &GC_ViewObj );
Expand Down Expand Up @@ -4880,7 +4892,7 @@ static Int InitLibrary ( StructInitInfo * module )
static StructInitInfo module = {
.type = MODULE_STATIC,
.name = "GAPROOT/lib/oper1.g",
.crc = 32938550,
.crc = 70528668,
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.postRestore = PostRestore,
Expand Down
52 changes: 32 additions & 20 deletions src/hpc/c_oper1.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef AVOID_PRECOMPILED
/* C file produced by GAC */
#include "compiled.h"
#define FILE_CRC "32938550"
#define FILE_CRC "70528668"

/* global variables used in handlers */
static GVar G_REREADING;
Expand Down Expand Up @@ -82,6 +82,8 @@ static GVar G_LEN__LIST;
static Obj GF_LEN__LIST;
static GVar G_APPEND__LIST__INTR;
static Obj GF_APPEND__LIST__INTR;
static GVar G_COPY__LIST__ENTRIES;
static Obj GF_COPY__LIST__ENTRIES;
static GVar G_CONV__STRING;
static Obj GF_CONV__STRING;
static GVar G_Print;
Expand Down Expand Up @@ -955,23 +957,31 @@ static Obj HdlrFunc3 (
}
if ( t_1 ) {

/* methods{[ narg + 5 + i + 1 .. narg + 5 + LEN_LIST( methods ) ]} := methods{[ i + 1 .. LEN_LIST( methods ) ]}; */
C_SUM_FIA( t_4, l_narg, INTOBJ_INT(5) )
C_SUM_FIA( t_3, t_4, l_i )
C_SUM_FIA( t_2, t_3, INTOBJ_INT(1) )
C_SUM_FIA( t_4, l_narg, INTOBJ_INT(5) )
t_6 = GF_LEN__LIST;
t_5 = CALL_1ARGS( t_6, l_methods );
CHECK_FUNC_RESULT( t_5 )
C_SUM_FIA( t_3, t_4, t_5 )
t_1 = Range2Check( t_2, t_3 );
C_SUM_FIA( t_4, l_i, INTOBJ_INT(1) )
t_6 = GF_LEN__LIST;
t_5 = CALL_1ARGS( t_6, l_methods );
CHECK_FUNC_RESULT( t_5 )
t_3 = Range2Check( t_4, t_5 );
t_2 = ElmsListCheck( l_methods, t_3 );
AsssListCheck( l_methods, t_1, t_2 );
/* COPY_LIST_ENTRIES( methods, i + 1, 1, methods, narg + 5 + i + 1, 1, LEN_LIST( methods ) - i ); */
t_1 = GF_COPY__LIST__ENTRIES;
t_2 = NEW_PLIST( T_PLIST, 7 );
SET_LEN_PLIST( t_2, 7 );
SET_ELM_PLIST( t_2, 1, l_methods );
CHANGED_BAG( t_2 );
C_SUM_FIA( t_3, l_i, INTOBJ_INT(1) )
SET_ELM_PLIST( t_2, 2, t_3 );
CHANGED_BAG( t_2 );
SET_ELM_PLIST( t_2, 3, INTOBJ_INT(1) );
SET_ELM_PLIST( t_2, 4, l_methods );
CHANGED_BAG( t_2 );
C_SUM_FIA( t_5, l_narg, INTOBJ_INT(5) )
C_SUM_FIA( t_4, t_5, l_i )
C_SUM_FIA( t_3, t_4, INTOBJ_INT(1) )
SET_ELM_PLIST( t_2, 5, t_3 );
CHANGED_BAG( t_2 );
SET_ELM_PLIST( t_2, 6, INTOBJ_INT(1) );
t_5 = GF_LEN__LIST;
t_4 = CALL_1ARGS( t_5, l_methods );
CHECK_FUNC_RESULT( t_4 )
C_DIFF_FIA( t_3, t_4, l_i )
SET_ELM_PLIST( t_2, 7, t_3 );
CHANGED_BAG( t_2 );
CALL_XARGS( t_1, t_2 );

}
/* fi */
Expand Down Expand Up @@ -4166,7 +4176,7 @@ static Obj HdlrFunc1 (
od;
fi;
if not REREADING or not replace then
methods{[ narg + 5 + i + 1 .. narg + 5 + LEN_LIST( methods ) ]} := methods{[ i + 1 .. LEN_LIST( methods ) ]};
COPY_LIST_ENTRIES( methods, i + 1, 1, methods, narg + 5 + i + 1, 1, LEN_LIST( methods ) - i );
fi;
if rel = true then
methods[i + 1] := RETURN_TRUE;
Expand Down Expand Up @@ -4735,6 +4745,7 @@ static Int PostRestore ( StructInitInfo * module )
G_RETURN__FALSE = GVarName( "RETURN_FALSE" );
G_LEN__LIST = GVarName( "LEN_LIST" );
G_APPEND__LIST__INTR = GVarName( "APPEND_LIST_INTR" );
G_COPY__LIST__ENTRIES = GVarName( "COPY_LIST_ENTRIES" );
G_CONV__STRING = GVarName( "CONV_STRING" );
G_Print = GVarName( "Print" );
G_ViewObj = GVarName( "ViewObj" );
Expand Down Expand Up @@ -4859,6 +4870,7 @@ static Int InitKernel ( StructInitInfo * module )
InitCopyGVar( "RETURN_FALSE", &GC_RETURN__FALSE );
InitFopyGVar( "LEN_LIST", &GF_LEN__LIST );
InitFopyGVar( "APPEND_LIST_INTR", &GF_APPEND__LIST__INTR );
InitFopyGVar( "COPY_LIST_ENTRIES", &GF_COPY__LIST__ENTRIES );
InitFopyGVar( "CONV_STRING", &GF_CONV__STRING );
InitFopyGVar( "Print", &GF_Print );
InitCopyGVar( "ViewObj", &GC_ViewObj );
Expand Down Expand Up @@ -4981,7 +4993,7 @@ static Int InitLibrary ( StructInitInfo * module )
static StructInitInfo module = {
.type = MODULE_STATIC,
.name = "GAPROOT/lib/oper1.g",
.crc = 32938550,
.crc = 70528668,
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.postRestore = PostRestore,
Expand Down

0 comments on commit a3f05db

Please sign in to comment.