8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 22:03:03 +01:00

big class Symbol cleanup

This commit is contained in:
alexpeshkoff 2004-03-31 18:02:50 +00:00
parent 10e311b36d
commit 4712bad7b5
3 changed files with 94 additions and 62 deletions

View File

@ -27,16 +27,17 @@
#include "../jrd/jrd.h" #include "../jrd/jrd.h"
#include "../jrd/val.h" #include "../jrd/val.h"
#include "../jrd/err_proto.h" #include "../jrd/err_proto.h"
#include "../jrd/sym_proto.h" #include "../jrd/sym.h"
#include "../jrd/thd_proto.h" #include "../jrd/thd_proto.h"
using namespace Jrd; using namespace Jrd;
static SSHORT hash_func(const SCHAR*); namespace {
SSHORT hash_func(const Firebird::string&);
}
void Symbol::insert()
void SYM_insert(Symbol* symbol)
{ {
/************************************** /**************************************
* *
@ -50,22 +51,24 @@ void SYM_insert(Symbol* symbol)
**************************************/ **************************************/
Database* dbb = GET_DBB; Database* dbb = GET_DBB;
const int h = hash_func(symbol->sym_string); const int h = hash_func(sym_string);
for (Symbol* old = dbb->dbb_hash_table[h]; old; old = old->sym_collision) { for (Symbol* old = dbb->dbb_hash_table[h]; old; old = old->sym_collision)
if (!strcmp(symbol->sym_string, old->sym_string)) { {
symbol->sym_homonym = old->sym_homonym; if (sym_string == old->sym_string)
old->sym_homonym = symbol; {
sym_homonym = old->sym_homonym;
old->sym_homonym = this;
return; return;
} }
} }
symbol->sym_collision = dbb->dbb_hash_table[h]; sym_collision = dbb->dbb_hash_table[h];
dbb->dbb_hash_table[h] = symbol; dbb->dbb_hash_table[h] = this;
} }
Symbol* SYM_lookup(const TEXT* string) Symbol* Symbol::lookup(const Firebird::string& string)
{ {
/************************************** /**************************************
* *
@ -82,7 +85,7 @@ Symbol* SYM_lookup(const TEXT* string)
for (Symbol* symbol = dbb->dbb_hash_table[hash_func(string)]; symbol; for (Symbol* symbol = dbb->dbb_hash_table[hash_func(string)]; symbol;
symbol = symbol->sym_collision) symbol = symbol->sym_collision)
{ {
if (!strcmp(string, symbol->sym_string)) if (string == symbol->sym_string)
return symbol; return symbol;
} }
@ -90,7 +93,7 @@ Symbol* SYM_lookup(const TEXT* string)
} }
void SYM_remove(Symbol* symbol) void Symbol::remove()
{ {
/************************************** /**************************************
* *
@ -104,20 +107,20 @@ void SYM_remove(Symbol* symbol)
**************************************/ **************************************/
Database* dbb = GET_DBB; Database* dbb = GET_DBB;
const int h = hash_func(symbol->sym_string); const int h = hash_func(sym_string);
for (Symbol** next = &dbb->dbb_hash_table[h]; *next; for (Symbol** next = &dbb->dbb_hash_table[h]; *next;
next = &(*next)->sym_collision) next = &(*next)->sym_collision)
{ {
if (symbol == *next) { if (this == *next) {
Symbol* homonym = symbol->sym_homonym; Symbol* homonym = sym_homonym;
if (homonym) { if (homonym) {
homonym->sym_collision = symbol->sym_collision; homonym->sym_collision = sym_collision;
*next = homonym; *next = homonym;
return; return;
} }
else { else {
*next = symbol->sym_collision; *next = sym_collision;
return; return;
} }
} }
@ -125,8 +128,8 @@ void SYM_remove(Symbol* symbol)
for (Symbol** ptr = &(*next)->sym_homonym; *ptr; for (Symbol** ptr = &(*next)->sym_homonym; *ptr;
ptr = &(*ptr)->sym_homonym) ptr = &(*ptr)->sym_homonym)
{ {
if (symbol == *ptr) { if (this == *ptr) {
*ptr = symbol->sym_homonym; *ptr = sym_homonym;
return; return;
} }
} }
@ -136,8 +139,9 @@ void SYM_remove(Symbol* symbol)
BUGCHECK(164); /* msg 164 failed to remove symbol from hash table */ BUGCHECK(164); /* msg 164 failed to remove symbol from hash table */
} }
namespace {
static SSHORT hash_func(const SCHAR* string) SSHORT hash_func(const Firebird::string& str)
{ {
/************************************** /**************************************
* *
@ -155,12 +159,12 @@ static SSHORT hash_func(const SCHAR* string)
int value = 0; int value = 0;
SCHAR c; for (const char *s = str.c_str(); *s; s++)
while ( (c = *string++) ) { {
value = (value << 1) + UPPER7(c); value = (value << 1) + UPPER7(*s);
} }
return ((value >= 0) ? value : -value) % HASH_SIZE; return ((value >= 0) ? value : -value) % HASH_SIZE;
} }
} //noname namespace

64
src/jrd/sym.h Normal file
View File

@ -0,0 +1,64 @@
/*
* PROGRAM: JRD Access Method
* MODULE: sym.h
* DESCRIPTION: Header file for sym.cpp
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#ifndef JRD_SYM_H
#define JRD_SYM_H
namespace Jrd {
/* symbol definitions */
class Symbol : public pool_alloc<type_sym>
{
private:
Symbol* sym_collision; /* collision pointer */
public:
typedef enum sym_t {
rel, /* relation block */
fld, /* field block */
fun, /* UDF function block */
prc, /* stored procedure block */
sql, /* SQL request cache block */
blr, /* BLR request cache block */
label /* CVC: I need to track labels if LEAVE is implemented. */
} SYM_T;
Firebird::string sym_string; // symbol value
SYM_T sym_type; /* symbol type */
BLK sym_object; /* general pointer to object */
Symbol* sym_homonym; /* homonym pointer */
public:
explicit Symbol(MemoryPool& p, const Firebird::string& val,
SYM_T type, BLK object)
: sym_collision(0), sym_string(p, val), sym_type(type),
sym_object(object), sym_homonym(0) { }
void insert();
static Symbol* lookup(const Firebird::string&);
void remove();
};
} //namespace Jrd
#endif // JRD_SYM_H

View File

@ -1,36 +0,0 @@
/*
* PROGRAM: JRD Access Method
* MODULE: sym_proto.h
* DESCRIPTION: Prototype header file for sym.cpp
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#ifndef JRD_SYM_PROTO_H
#define JRD_SYM_PROTO_H
namespace Jrd {
class Symbol;
}
void SYM_insert(Jrd::Symbol*);
Jrd::Symbol* SYM_lookup(const TEXT*);
void SYM_remove(Jrd::Symbol*);
#endif // JRD_SYM_PROTO_H