7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.13 1997/04/09 08:29:35 scrappy Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.14 1997/04/21 04:31:53 vadim Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -288,47 +288,45 @@ textne(struct varlena *arg1, struct varlena *arg2)
288
288
/* text_lt()
289
289
* Comparison function for text strings.
290
290
* Includes locale support, but must copy strings to temporary memory
291
- * to allow null-termination for inputs to strcoll().
292
- * XXX HACK code for textlen() indicates that there can be embedded nulls
293
- * but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
291
+ * to allow null-termination for inputs to strcoll().
294
292
*/
295
293
bool
296
294
text_lt (struct varlena * arg1 , struct varlena * arg2 )
297
295
{
298
- bool result ;
299
-
300
- int cval ;
301
296
int len ;
302
297
#ifdef UNSIGNED_CHAR_TEXT
303
298
unsigned
304
299
#endif
305
300
char * a1p , * a2p ;
301
+ #ifdef USE_LOCALE
302
+ int cval ;
303
+ #endif
306
304
307
305
if (arg1 == NULL || arg2 == NULL )
308
306
return ((bool ) FALSE);
309
307
310
308
len = (((VARSIZE (arg1 ) <= VARSIZE (arg2 ))? VARSIZE (arg1 ): VARSIZE (arg2 ))- VARHDRSZ );
311
309
312
310
#ifdef USE_LOCALE
313
- if (!PointerIsValid (a1p = PALLOC (len + 1 ))
314
- || !PointerIsValid (a2p = PALLOC (len + 1 ))) {
315
- elog (WARN ,"Unable to allocate memory for text comparison" ,NULL );
316
- return (FALSE);
317
- };
311
+
312
+ a1p = palloc (len + 1 );
313
+ a2p = palloc (len + 1 );
318
314
319
315
memcpy (a1p , VARDATA (arg1 ), len );
320
316
* (a1p + len ) = '\0' ;
321
317
memcpy (a2p , VARDATA (arg2 ), len );
322
318
* (a2p + len ) = '\0' ;
323
319
324
320
cval = strcoll (a1p ,a2p );
325
- result = ((cval < 0 ) || ((cval == 0 ) && (VARSIZE (arg1 ) < VARSIZE (arg2 ))));
321
+
322
+ pfree (a1p );
323
+ pfree (a2p );
326
324
327
- PFREE ( a1p );
328
- PFREE ( a2p );
325
+ return (( bool ) ( ( cval < 0 ) ||
326
+ ( ( cval == 0 ) && ( VARSIZE ( arg1 ) < VARSIZE ( arg2 )) ) ) );
329
327
330
- return (result );
331
328
#else
329
+
332
330
a1p = (unsigned char * )VARDATA (arg1 );
333
331
a2p = (unsigned char * )VARDATA (arg2 );
334
332
@@ -338,53 +336,53 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
338
336
len -- ;
339
337
};
340
338
return ((bool ) (len ? (* a1p < * a2p ): (VARSIZE (arg1 ) < VARSIZE (arg2 ))));
339
+
341
340
#endif
341
+
342
342
} /* text_lt() */
343
343
344
344
/* text_le()
345
345
* Comparison function for text strings.
346
346
* Includes locale support, but must copy strings to temporary memory
347
- * to allow null-termination for inputs to strcoll().
348
- * XXX HACK code for textlen() indicates that there can be embedded nulls
349
- * but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
347
+ * to allow null-termination for inputs to strcoll().
350
348
*/
351
349
bool
352
350
text_le (struct varlena * arg1 , struct varlena * arg2 )
353
351
{
354
- bool result ;
355
-
356
- int cval ;
357
352
int len ;
358
353
#ifdef UNSIGNED_CHAR_TEXT
359
354
unsigned
360
355
#endif
361
356
char * a1p , * a2p ;
357
+ #ifdef USE_LOCALE
358
+ int cval ;
359
+ #endif
362
360
363
361
if (arg1 == NULL || arg2 == NULL )
364
362
return ((bool ) 0 );
365
363
366
364
len = (((VARSIZE (arg1 ) <= VARSIZE (arg2 ))? VARSIZE (arg1 ): VARSIZE (arg2 ))- VARHDRSZ );
367
365
368
366
#ifdef USE_LOCALE
369
- if (!PointerIsValid (a1p = PALLOC (len + 1 ))
370
- || !PointerIsValid (a2p = PALLOC (len + 1 ))) {
371
- elog (WARN ,"Unable to allocate memory for text comparison" ,NULL );
372
- return (FALSE);
373
- };
367
+
368
+ a1p = palloc (len + 1 );
369
+ a2p = palloc (len + 1 );
374
370
375
371
memcpy (a1p , VARDATA (arg1 ), len );
376
372
* (a1p + len ) = '\0' ;
377
373
memcpy (a2p , VARDATA (arg2 ), len );
378
374
* (a2p + len ) = '\0' ;
379
375
380
376
cval = strcoll (a1p ,a2p );
381
- result = ((cval < 0 ) || ((cval == 0 ) && (VARSIZE (arg1 ) <= VARSIZE (arg2 ))));
377
+
378
+ pfree (a1p );
379
+ pfree (a2p );
382
380
383
- PFREE ( a1p );
384
- PFREE ( a2p );
381
+ return (( bool ) ( ( cval < 0 ) ||
382
+ ( ( cval == 0 ) && ( VARSIZE ( arg1 ) <= VARSIZE ( arg2 )) ) ) );
385
383
386
- return (result );
387
384
#else
385
+
388
386
a1p = (unsigned char * )VARDATA (arg1 );
389
387
a2p = (unsigned char * )VARDATA (arg2 );
390
388
@@ -395,7 +393,9 @@ text_le(struct varlena *arg1, struct varlena *arg2)
395
393
};
396
394
397
395
return ((bool ) (len ? (* a1p <= * a2p ): (VARSIZE (arg1 ) <= VARSIZE (arg2 ))));
396
+
398
397
#endif
398
+
399
399
} /* text_le() */
400
400
401
401
bool
0 commit comments