Added gphFindParse(), which takes a string length parameter.

This is useful for hash lookups while parsing a const string, to avoid
 having to copy and nil-terminate it.
This commit is contained in:
Andrew Johnson
2012-04-27 13:21:33 -04:00
committed by Michael Davidsaver
parent 68dfeb76c0
commit 0ab891fca4
2 changed files with 18 additions and 10 deletions

View File

@@ -5,7 +5,7 @@
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* $Revision-Id$ */
/* Author: Marty Kraimer Date: 04-07-94 */
@@ -37,6 +37,8 @@ epicsShareFunc void epicsShareAPI
gphInitPvt(struct gphPvt **ppvt, int tableSize);
epicsShareFunc GPHENTRY * epicsShareAPI
gphFind(struct gphPvt *pvt, const char *name, void *pvtid);
epicsShareFunc GPHENTRY * epicsShareAPI
gphFindParse(struct gphPvt *pvt, const char *name, size_t len, void *pvtid);
epicsShareFunc GPHENTRY * epicsShareAPI
gphAdd(struct gphPvt *pvt, const char *name, void *pvtid);
epicsShareFunc void epicsShareAPI

View File

@@ -4,12 +4,12 @@
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* $Revision-Id$ */
/* Author: Marty Kraimer Date: 04-07-94 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -34,7 +34,7 @@ typedef struct gphPvt {
#define MIN_SIZE 256
#define DEFAULT_SIZE 512
#define MAX_SIZE 65536
void epicsShareAPI gphInitPvt(gphPvt **ppvt, int size)
{
gphPvt *pgphPvt;
@@ -59,7 +59,7 @@ void epicsShareAPI gphInitPvt(gphPvt **ppvt, int size)
return;
}
GPHENTRY * epicsShareAPI gphFind(gphPvt *pgphPvt, const char *name, void *pvtid)
GPHENTRY * epicsShareAPI gphFindParse(gphPvt *pgphPvt, const char *name, size_t len, void *pvtid)
{
ELLLIST **paplist;
ELLLIST *gphlist;
@@ -69,7 +69,7 @@ GPHENTRY * epicsShareAPI gphFind(gphPvt *pgphPvt, const char *name, void *pvtid)
if (pgphPvt == NULL) return NULL;
paplist = pgphPvt->paplist;
hash = epicsMemHash((char *)&pvtid, sizeof(void *), 0);
hash = epicsStrHash(name, hash) & pgphPvt->mask;
hash = epicsMemHash(name, len, hash) & pgphPvt->mask;
epicsMutexMustLock(pgphPvt->lock);
gphlist = paplist[hash];
@@ -81,14 +81,20 @@ GPHENTRY * epicsShareAPI gphFind(gphPvt *pgphPvt, const char *name, void *pvtid)
while (pgphNode) {
if (pvtid == pgphNode->pvtid &&
strcmp(name, pgphNode->name) == 0) break;
strlen(pgphNode->name) == len &&
strncmp(name, pgphNode->name, len) == 0) break;
pgphNode = (GPHENTRY *) ellNext((ELLNODE *)pgphNode);
}
epicsMutexUnlock(pgphPvt->lock);
return pgphNode;
}
GPHENTRY * epicsShareAPI gphFind(gphPvt *pgphPvt, const char *name, void *pvtid)
{
return gphFindParse(pgphPvt, name, strlen(name), pvtid);
}
GPHENTRY * epicsShareAPI gphAdd(gphPvt *pgphPvt, const char *name, void *pvtid)
{
ELLLIST **paplist;
@@ -133,7 +139,7 @@ GPHENTRY * epicsShareAPI gphAdd(gphPvt *pgphPvt, const char *name, void *pvtid)
epicsMutexUnlock(pgphPvt->lock);
return (pgphNode);
}
void epicsShareAPI gphDelete(gphPvt *pgphPvt, const char *name, void *pvtid)
{
ELLLIST **paplist;
@@ -167,7 +173,7 @@ void epicsShareAPI gphDelete(gphPvt *pgphPvt, const char *name, void *pvtid)
epicsMutexUnlock(pgphPvt->lock);
return;
}
void epicsShareAPI gphFreeMem(gphPvt *pgphPvt)
{
ELLLIST **paplist;