gecko/layout/tables/SpanningCellSorter.h
Ehsan Akhgari 0fd9123eac Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

96 lines
3.1 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:cindent:ts=4:et:sw=4:
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Code to sort cells by their colspan, used by BasicTableLayoutStrategy.
*/
#include "pldhash.h"
#include "nsDebug.h"
#include "StackArena.h"
class nsIPresShell;
/**
* The SpanningCellSorter is responsible for accumulating lists of cells
* with colspans so that those cells can later be enumerated, sorted
* from lowest number of columns spanned to highest. It does not use a
* stable sort (in fact, it currently reverses).
*/
class NS_STACK_CLASS SpanningCellSorter {
public:
SpanningCellSorter();
~SpanningCellSorter();
struct Item {
int32_t row, col;
Item *next;
};
/**
* Add a cell to the sorter. Returns false on out of memory.
* aColSpan is the number of columns spanned, and aRow/aCol are the
* position of the cell in the table (for GetCellInfoAt).
*/
bool AddCell(int32_t aColSpan, int32_t aRow, int32_t aCol);
/**
* Get the next *list* of cells. Each list contains all the cells
* for a colspan value, and the lists are given in order from lowest
* to highest colspan. The colspan value is filled in to *aColSpan.
*/
Item* GetNext(int32_t *aColSpan);
private:
enum State { ADDING, ENUMERATING_ARRAY, ENUMERATING_HASH, DONE };
State mState;
// store small colspans in an array for fast sorting and
// enumeration, and large colspans in a hash table
enum { ARRAY_BASE = 2 };
enum { ARRAY_SIZE = 8 };
Item *mArray[ARRAY_SIZE];
int32_t SpanToIndex(int32_t aSpan) { return aSpan - ARRAY_BASE; }
int32_t IndexToSpan(int32_t aIndex) { return aIndex + ARRAY_BASE; }
bool UseArrayForSpan(int32_t aSpan) {
NS_ASSERTION(SpanToIndex(aSpan) >= 0, "cell without colspan");
return SpanToIndex(aSpan) < ARRAY_SIZE;
}
PLDHashTable mHashTable;
struct HashTableEntry : public PLDHashEntryHdr {
int32_t mColSpan;
Item *mItems;
};
static PLDHashTableOps HashTableOps;
static PLDHashNumber
HashTableHashKey(PLDHashTable *table, const void *key);
static bool
HashTableMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
const void *key);
static PLDHashOperator
FillSortedArray(PLDHashTable *table, PLDHashEntryHdr *hdr,
uint32_t number, void *arg);
static int SortArray(const void *a, const void *b, void *closure);
/* state used only during enumeration */
uint32_t mEnumerationIndex; // into mArray or mSortedHashTable
HashTableEntry **mSortedHashTable;
/*
* operator new is forbidden since we use the pres shell's stack
* memory, which much be pushed and popped at points matching a
* push/pop on the C++ stack.
*/
void* operator new(size_t sz) CPP_THROW_NEW { return nullptr; }
};