diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 71d76a6fc2f0bd931c8273dec88a17f7d099fce3..30961f4f549e2a4ebb81c7caf120d651c1b00e6e 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.19 1997/08/19 21:28:49 momjian Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.20 1997/08/24 23:07:26 momjian Exp $
  *
  * NOTES
  *    The old interface functions have been converted to macros
@@ -695,26 +695,20 @@ heap_getattr(HeapTuple tup,
     if (attnum > (int) tup->t_natts) {
         *isnull = true;
         return ((char *) NULL);
+    } else if (attnum > 0) {
+	/* ----------------
+	 *  take care of user defined attributes
+	 * ----------------
+	 */
+        return fastgetattr(tup, attnum, tupleDesc, isnull);
+    } else {
+	/* ----------------
+	 *  take care of system attributes
+	 * ----------------
+	 */
+	*isnull = false;
+	return heap_getsysattr(tup, b, attnum);
     }
-    
-    /* ----------------
-     *  take care of user defined attributes
-     * ----------------
-     */
-    if (attnum > 0) {
-        char  *datum;
-        datum = fastgetattr(tup, attnum, tupleDesc, isnull);
-        
-        return (datum);
-    }
-    
-    /* ----------------
-     *  take care of system attributes
-     * ----------------
-     */
-    *isnull = false;
-    return
-        heap_getsysattr(tup, b, attnum);
 }
 
 /* ----------------
diff --git a/src/backend/access/common/heapvalid.c b/src/backend/access/common/heapvalid.c
index f0b4f3f3458f7da25f923093e82823403c30e1ec..edb1e07187ec920d33946fa37bf916d0f8afd78e 100644
--- a/src/backend/access/common/heapvalid.c
+++ b/src/backend/access/common/heapvalid.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.13 1997/03/28 07:03:53 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.14 1997/08/24 23:07:26 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,6 +22,7 @@
 #include <utils/rel.h>
 #include <utils/tqual.h>
 #include <storage/bufmgr.h>
+#include <utils/builtins.h>
 
 /* ----------------
  *	heap_keytest
@@ -53,7 +54,9 @@ heap_keytest(HeapTuple t,
 	    return (false);
 	}
 
-	if (keys->sk_flags & SK_COMMUTE)
+	if (keys->sk_func == (func_ptr)oideq)	/* optimization */
+	    test = (keys->sk_argument == atp);
+	else if (keys->sk_flags & SK_COMMUTE)
 	    test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure,
 				    keys->sk_argument, atp);
 	else
diff --git a/src/backend/storage/ipc/s_lock.c b/src/backend/storage/ipc/s_lock.c
index 7a81185162525bf7a1b3310ce1b590b106d927cd..85477cce6188df1ba02f2d474de4c25ea117b25c 100644
--- a/src/backend/storage/ipc/s_lock.c
+++ b/src/backend/storage/ipc/s_lock.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/s_lock.c,v 1.19 1997/08/20 00:50:11 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/s_lock.c,v 1.20 1997/08/24 23:07:28 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -44,12 +44,6 @@
 
 #if defined(HAS_TEST_AND_SET)
 
-# if defined(__alpha__) && defined(linux)
-static long int tas(slock_t *lock);
-# else
-static int tas(slock_t *lock);
-#endif
-
 #if defined (nextstep)
 /*
  * NEXTSTEP (mach)
@@ -167,6 +161,8 @@ S_LOCK_FREE(slock_t *lock)
     defined(sparc_solaris)
 /* for xxxxx_solaris, this is defined in port/.../tas.s */
 
+static int tas(slock_t *lock);
+
 void
 S_LOCK(slock_t *lock)
 {
@@ -233,6 +229,8 @@ S_INIT_LOCK(slock_t *lock)
 */
 static slock_t clear_lock = { -1, -1, -1, -1 };
 
+static int tas(slock_t *lock);
+
 void
 S_LOCK(slock_t *lock)
 {
@@ -268,6 +266,8 @@ S_LOCK_FREE(slock_t *lock)
  
 #if defined(sun3)
 
+static int tas(slock_t *lock);
+
 void    
 S_LOCK(slock_t *lock)
 {
@@ -320,6 +320,8 @@ tas_dummy()
 #define asm(x)  __asm__(x)
 #endif 
 
+static int tas(slock_t *lock);
+
 static int
 tas_dummy()
 {
@@ -383,19 +385,14 @@ S_INIT_LOCK(unsigned char *addr)
 
 #if defined(NEED_I386_TAS_ASM)
 
-static int
-tas(slock_t *m)
-{
-    slock_t res;
-    __asm__("xchgb %0,%1":"=q" (res),"=m" (*m):"0" (0x1));
-    return(res);
-}
-
 void
 S_LOCK(slock_t *lock)
 {
-    while (tas(lock))
-	;
+    slock_t res;
+
+    do{
+	__asm__("xchgb %0,%1":"=q" (res),"=m" (*lock):"0" (0x1));
+    }while(res != 0);
 }
 
 void
@@ -415,31 +412,26 @@ S_INIT_LOCK(slock_t *lock)
 
 #if defined(__alpha__) && defined(linux)
 
-static long int
-tas(slock_t *m)
-{
-    slock_t res;
-    __asm__("         ldq   $0, %0            \n\
-                      bne   $0, already_set   \n\
-                      ldq_l $0, %0            \n\
-                      bne   $0, already_set   \n\
-                      or    $31, 1, $0        \n\
-                      stq_c $0, %0            \n\
-                      beq   $0, stqc_fail     \n\
-        success:      bis   $31, $31, %1      \n\
-                      mb                      \n\
-                      jmp   $31, end          \n\
-        stqc_fail:    or    $31, 1, $0        \n\
-        already_set:  bis   $0, $0, %1        \n\
-        end:          nop      " : "=m" (*m), "=r" (res) :: "0" );
-    return(res);
-}
-
 void
 S_LOCK(slock_t *lock)
 {
-    while (tas(lock))
-	;
+    slock_t res;
+
+    do{
+	__asm__("    ldq   $0, %0	     \n\
+		     bne   $0, already_set   \n\
+		     ldq_l $0, %0	     \n\
+		     bne   $0, already_set   \n\
+		     or    $31, 1, $0	     \n\
+		     stq_c $0, %0	     \n\
+		     beq   $0, stqc_fail     \n\
+	success:     bis   $31, $31, %1      \n\
+		     mb		             \n\
+		     jmp   $31, end	     \n\
+	stqc_fail:   or    $31, 1, $0	     \n\
+	already_set: bis   $0, $0, %1	     \n\
+	end:	     nop      " : "=m" (*lock), "=r" (res) :: "0" );
+    }while(res != 0);
 }
 
 void
@@ -459,56 +451,16 @@ S_INIT_LOCK(slock_t *lock)
 
 #if defined(linux) && defined(sparc)
  
-static int 
-tas(slock_t *m)
-{
-  slock_t res;
-  __asm__("ldstub [%1], %0"
-	  : "=&r" (res)
-	  : "r" (m));
-  return (res != 0);
-}
-
 void
 S_LOCK(slock_t *lock)
 {
-    while (tas(lock))
-	;
-}
-
-void
-S_UNLOCK(slock_t *lock)
-{
-    *lock = 0;
-}
-
-void
-S_INIT_LOCK(slock_t *lock)
-{
-    S_UNLOCK(lock);
-}
-
-#endif /* defined(linux) && defined(sparc) */
-
-#if defined(NEED_NS32K_TAS_ASM)
-
-static int
-tas(slock_t *m)
-{
-    slock_t res = 0;
-    __asm__("movd 8(fp), r1");
-    __asm__("movqd 0, r0");
-    __asm__("sbitd r0, 0(r1)");
-    __asm__("sprb us, %0" : "=r" (res));
-    res =  (res >> 5) & 1;
-    return res;
-}
+    slock_t res;
 
-void
-S_LOCK(slock_t *lock)
-{
-    while (tas(lock))
-	;
+    do{
+	__asm__("ldstub [%1], %0"
+		  : "=&r" (res)
+		  : "r" (lock));
+    }while(!res != 0);
 }
 
 void
@@ -523,7 +475,7 @@ S_INIT_LOCK(slock_t *lock)
     S_UNLOCK(lock);
 }
 
-#endif /* NEED_NS32K_TAS_ASM */
+#endif /* defined(linux) && defined(sparc) */
 
 #if defined(linux) && defined(PPC)
 
diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index ac1428257418d0e68838aa3ebd7879ec0fbc01d3..98d1c59d5f053fca5430b2eca706b43eb5f10c34 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/storage/page/bufpage.c,v 1.7 1997/08/19 21:33:33 momjian Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/storage/page/bufpage.c,v 1.8 1997/08/24 23:07:30 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,43 +31,6 @@ static void PageIndexTupleDeleteAdjustLinePointers(PageHeader phdr,
 
 static bool PageManagerShuffle = true;	/* default is shuffle mode */
 
-/* ----------------------------------------------------------------
- *			Buffer support functions
- * ----------------------------------------------------------------
- */
-/*
- * BufferGetPageSize --
- *	Returns the page size within a buffer.
- *
- * Notes:
- *	Assumes buffer is valid.
- *
- *	The buffer can be a raw disk block and need not contain a valid
- *	(formatted) disk page.
- */
-Size
-BufferGetPageSize(Buffer buffer)
-{
-    Size	pageSize;
-    
-    Assert(BufferIsValid(buffer));
-    pageSize = BLCKSZ;	/* XXX dig out of buffer descriptor */
-    
-    Assert(PageSizeIsValid(pageSize));
-    return (pageSize);
-}
-
-/*
- * BufferGetPage --
- *	Returns the page associated with a buffer.
- */
-Page
-BufferGetPage(Buffer buffer)
-{
-    return (Page) BufferGetBlock(buffer);
-}
-
-
 /* ----------------------------------------------------------------
  *			Page support functions
  * ----------------------------------------------------------------
@@ -94,31 +57,6 @@ PageInit(Page page, Size pageSize, Size specialSize)
     PageSetPageSize(page, pageSize);
 }
 
-/*
- * PageGetItem --
- *	Retrieves an item on the given page.
- *
- * Note:
- *	This does change the status of any of the resources passed.
- *	The semantics may change in the future.
- */
-Item
-PageGetItem(Page page, ItemId itemId)
-{
-    Item	item;
-    
-    Assert(PageIsValid(page));
-/*    Assert(itemId->lp_flags & LP_USED); */
-    if(!(itemId->lp_flags & LP_USED)) {
-	elog(NOTICE, "LP_USED assertion failed.  dumping core.");
-	abort();
-    }
-    
-    item = (Item)(((char *)page) + itemId->lp_off);
-    
-    return (item);
-}
-
 /*
  * PageAddItem --
  *	Adds item to the given page.
diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c
index a89edac79bb0c70fe2b37c798e872f4eb7ef0517..977fe87fbcad52985cad8f191722e987f199b641 100644
--- a/src/backend/utils/adt/oid.c
+++ b/src/backend/utils/adt/oid.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.7 1997/07/24 20:16:17 momjian Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.8 1997/08/24 23:07:35 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -96,6 +96,10 @@ char *oidout(Oid o)
  *   PUBLIC ROUTINES                                                         *
  *****************************************************************************/
 
+/*
+ * If you change this function, change heap_keytest()
+ * because we have hardcoded this in there as an optimization
+ */
 bool oideq(Oid arg1, Oid arg2)
 {
     return(arg1 == arg2);
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 10289e032315475fbb89a20fcdb5e67f1bb45622..be7afe0a5f23e0e93187ce93c5195e0bb22ab7fb 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.7 1997/08/19 21:34:58 momjian Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.8 1997/08/24 23:07:42 momjian Exp $
  *
  * Notes:
  *	XXX This needs to use exception.h to handle recovery when
@@ -656,8 +656,19 @@ InitSysCache(char *relname,
      *  and the LRU tuple list
      * ----------------
      */
-    for (i = 0; i <= NCCBUCK; ++i) {
-      cp->cc_cache[i] = DLNewList();
+    {
+	/*
+	 *  We can only do this optimization because the number of hash
+         *  buckets never changes.  Without it, we call malloc() too much.
+         *  We could move this to dllist.c, but the way we do this is not
+         *  dynamic/portabl, so why allow other routines to use it.
+         */
+    	void *cache_begin = malloc((NCCBUCK+1)*sizeof(Dllist));
+	for (i = 0; i <= NCCBUCK; ++i) {
+	    cp->cc_cache[i] = cache_begin + i * sizeof(Dllist);
+	    cp->cc_cache[i]->dll_head = 0;
+	    cp->cc_cache[i]->dll_tail = 0;
+	}
     }
     
     cp->cc_lrulist = DLNewList();
diff --git a/src/backend/utils/mmgr/oset.c b/src/backend/utils/mmgr/oset.c
index d413cb5cb6f078d7c6aa99f38472680195d93634..6b42ee45d7291defa31bc299654e1c60931f04e7 100644
--- a/src/backend/utils/mmgr/oset.c
+++ b/src/backend/utils/mmgr/oset.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/oset.c,v 1.2 1997/08/19 21:35:59 momjian Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/oset.c,v 1.3 1997/08/24 23:07:50 momjian Exp $
  *
  * NOTE
  *    XXX This is a preliminary implementation which lacks fail-fast
@@ -20,7 +20,6 @@
 #include "utils/memutils.h"	/* where declarations of this file goes */
 
 static Pointer OrderedElemGetBase(OrderedElem elem);
-static void OrderedElemInit(OrderedElem elem, OrderedSet set);
 static void OrderedElemPush(OrderedElem elem);
 static void OrderedElemPushHead(OrderedElem elem);
 
@@ -49,18 +48,6 @@ OrderedSetInit(OrderedSet set, Offset offset)
     set->offset = offset;
 }
 
-/*
- * OrderedElemInit --
- */
-static void
-OrderedElemInit(OrderedElem elem, OrderedSet set)
-{
-    elem->set = set;
-    /* mark as unattached */
-    elem->next = NULL;
-    elem->prev = NULL;
-}
-
 /*
  * OrderedSetContains --
  *	True iff ordered set contains given element.
@@ -148,7 +135,10 @@ OrderedElemPop(OrderedElem elem)
 void
 OrderedElemPushInto(OrderedElem elem, OrderedSet set)
 {
-    OrderedElemInit(elem, set);
+    elem->set = set;
+    /* mark as unattached */
+    elem->next = NULL;
+    elem->prev = NULL;
     OrderedElemPush(elem);
 }
 
diff --git a/src/include/c.h b/src/include/c.h
index eaf1ee7b03a940ae00a450972a115c1a0757ce6b..f56f1ea5da0e34d514e5d27a85043ef2d0ca5a64 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -7,7 +7,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: c.h,v 1.14 1997/08/12 20:16:17 momjian Exp $
+ * $Id: c.h,v 1.15 1997/08/24 23:07:56 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -686,8 +686,7 @@ typedef struct Exception {
  *	Does string copy, and forces terminating NULL
  */
 /* we do this so if the macro is used in an if action, it will work */
-#define strNcpy(dest,src,len)	do \
-		{strncpy((dest),(src),(len));*((dest) + (len)) = '\0';} while (0)
+#define strNcpy(dst,src,len)	(strncpy((dst),(src),(len)),*((dst)+(len))='\0',dst)
 
 /* ----------------------------------------------------------------
  *		Section 9: externs
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index 7304b6115aa2b410c57cc7bb6e9a9761c33c443c..b0408106ef7a18853eda854a57413dd8fdb80c14 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: bufpage.h,v 1.8 1997/08/19 21:39:47 momjian Exp $
+ * $Id: bufpage.h,v 1.9 1997/08/24 23:08:01 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -233,17 +233,50 @@ typedef enum {
 #define PageGetSpecialPointer(page) \
     (AssertMacro(PageIsValid(page)) ? \
      (char *) ((char *) (page) + ((PageHeader) (page))->pd_special) \
-     : (char *) 0)
+     : (char *)0 )
 
+/*
+ * PageGetItem --
+ *	Retrieves an item on the given page.
+ *
+ * Note:
+ *	This does change the status of any of the resources passed.
+ *	The semantics may change in the future.
+ */
+#define PageGetItem(page, itemId) \
+    (AssertMacro(PageIsValid(page)) ? \
+     AssertMacro(itemId->lp_flags & LP_USED) ? \
+    (Item)(((char *)page) + itemId->lp_off) : false : false)
+
+/*
+ * BufferGetPageSize --
+ *	Returns the page size within a buffer.
+ *
+ * Notes:
+ *	Assumes buffer is valid.
+ *
+ *	The buffer can be a raw disk block and need not contain a valid
+ *	(formatted) disk page.
+ */
+/* XXX dig out of buffer descriptor */
+#define BufferGetPageSize(buffer) \
+    (AssertMacro(BufferIsValid(buffer)) ? \
+     AssertMacro(PageSizeIsValid(pageSize)) ? \
+     ((Size)BLCKSZ) : false : false)
+
+/*
+ * BufferGetPage --
+ *	Returns the page associated with a buffer.
+ */
+#define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer))
+
+     
 /* ----------------------------------------------------------------
  *	extern declarations
  * ----------------------------------------------------------------
  */
 
-extern Size BufferGetPageSize(Buffer buffer);
-extern Page BufferGetPage(Buffer buffer);
 extern void PageInit(Page page, Size pageSize, Size specialSize);
-extern Item PageGetItem(Page page, ItemId itemId);
 extern OffsetNumber PageAddItem(Page page, Item item, Size size,
 			 OffsetNumber offsetNumber, ItemIdFlags flags);
 extern Page PageGetTempPage(Page page, Size specialSize);