@@ -111,22 +111,24 @@ loop2:
111111 return glob .String ()
112112}
113113
114- func load (ctx sqlite3.Context , i int , expr string ) (* regexp.Regexp , error ) {
114+ func load (ctx sqlite3.Context , arg []sqlite3. Value , i int ) (* regexp.Regexp , error ) {
115115 re , ok := ctx .GetAuxData (i ).(* regexp.Regexp )
116116 if ! ok {
117- r , err := regexp .Compile (expr )
118- if err != nil {
119- return nil , err
117+ re , ok = arg [i ].Pointer ().(* regexp.Regexp )
118+ if ! ok {
119+ r , err := regexp .Compile (arg [i ].Text ())
120+ if err != nil {
121+ return nil , err
122+ }
123+ re = r
120124 }
121- re = r
122- ctx .SetAuxData (0 , r )
125+ ctx .SetAuxData (i , re )
123126 }
124127 return re , nil
125128}
126129
127130func regex (ctx sqlite3.Context , arg ... sqlite3.Value ) {
128- _ = arg [1 ] // bounds check
129- re , err := load (ctx , 0 , arg [0 ].Text ())
131+ re , err := load (ctx , arg , 0 )
130132 if err != nil {
131133 ctx .ResultError (err )
132134 return // notest
@@ -136,18 +138,17 @@ func regex(ctx sqlite3.Context, arg ...sqlite3.Value) {
136138}
137139
138140func regexLike (ctx sqlite3.Context , arg ... sqlite3.Value ) {
139- re , err := load (ctx , 1 , arg [ 1 ]. Text () )
141+ re , err := load (ctx , arg , 1 )
140142 if err != nil {
141143 ctx .ResultError (err )
142144 return // notest
143145 }
144-
145146 text := arg [0 ].RawText ()
146147 ctx .ResultBool (re .Match (text ))
147148}
148149
149150func regexCount (ctx sqlite3.Context , arg ... sqlite3.Value ) {
150- re , err := load (ctx , 1 , arg [ 1 ]. Text () )
151+ re , err := load (ctx , arg , 1 )
151152 if err != nil {
152153 ctx .ResultError (err )
153154 return // notest
@@ -162,7 +163,7 @@ func regexCount(ctx sqlite3.Context, arg ...sqlite3.Value) {
162163}
163164
164165func regexSubstr (ctx sqlite3.Context , arg ... sqlite3.Value ) {
165- re , err := load (ctx , 1 , arg [ 1 ]. Text () )
166+ re , err := load (ctx , arg , 1 )
166167 if err != nil {
167168 ctx .ResultError (err )
168169 return // notest
@@ -187,7 +188,7 @@ func regexSubstr(ctx sqlite3.Context, arg ...sqlite3.Value) {
187188}
188189
189190func regexInstr (ctx sqlite3.Context , arg ... sqlite3.Value ) {
190- re , err := load (ctx , 1 , arg [ 1 ]. Text () )
191+ re , err := load (ctx , arg , 1 )
191192 if err != nil {
192193 ctx .ResultError (err )
193194 return // notest
@@ -215,16 +216,14 @@ func regexInstr(ctx sqlite3.Context, arg ...sqlite3.Value) {
215216}
216217
217218func regexReplace (ctx sqlite3.Context , arg ... sqlite3.Value ) {
218- _ = arg [2 ] // bounds check
219-
220- re , err := load (ctx , 1 , arg [1 ].Text ())
219+ re , err := load (ctx , arg , 1 )
221220 if err != nil {
222221 ctx .ResultError (err )
223222 return // notest
224223 }
225224
226- text := arg [0 ].RawText ()
227225 repl := arg [2 ].RawText ()
226+ text := arg [0 ].RawText ()
228227 var pos , n int
229228 if len (arg ) > 3 {
230229 pos = arg [3 ].Int ()
0 commit comments