Author: jmorlan
Date: Sun Jul 27 15:08:18 2008
New Revision: 34858
URL:
http://svn.reactos.org/svn/reactos?rev=34858&view=rev
Log:
- Work with screen buffer data using pointers rather than offsets; remove confusing
GET_CELL_BUFFER and SET_CELL_BUFFER macros.
- CsrFreeProcessData: Merge two ifs with the same condition.
- Use the pointer-to-pointer trick to simplify linked list handling in CsrFreeProcessData,
IntInsertAliasHeader, IntInsertAliasEntry, and IntDeleteAliasEntry.
Modified:
trunk/reactos/subsystems/win32/csrss/api/process.c
trunk/reactos/subsystems/win32/csrss/include/conio.h
trunk/reactos/subsystems/win32/csrss/win32csr/alias.c
trunk/reactos/subsystems/win32/csrss/win32csr/conio.c
trunk/reactos/subsystems/win32/csrss/win32csr/guiconsole.c
trunk/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c
Modified: trunk/reactos/subsystems/win32/csrss/api/process.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/api…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/api/process.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/api/process.c [iso-8859-1] Sun Jul 27 15:08:18
2008
@@ -129,18 +129,16 @@
{
ULONG hash;
UINT c;
- PCSRSS_PROCESS_DATA pProcessData, pPrevProcessData = NULL;
+ PCSRSS_PROCESS_DATA pProcessData, *pPrevLink;
hash = ((ULONG_PTR)Pid >> 2) % (sizeof(ProcessData) / sizeof(*ProcessData));
+ pPrevLink = &ProcessData[hash];
LOCK;
- pProcessData = ProcessData[hash];
-
- while (pProcessData && pProcessData->ProcessId != Pid)
- {
- pPrevProcessData = pProcessData;
- pProcessData = pProcessData->next;
+ while ((pProcessData = *pPrevLink) && pProcessData->ProcessId != Pid)
+ {
+ pPrevLink = &pProcessData->next;
}
if (pProcessData)
@@ -150,10 +148,6 @@
{
NtClose(pProcessData->Process);
}
- if (pProcessData->Console)
- {
- RemoveEntryList(&pProcessData->ProcessEntry);
- }
if (pProcessData->HandleTable)
{
for (c = 0; c < pProcessData->HandleTableSize; c++)
@@ -168,6 +162,7 @@
RtlDeleteCriticalSection(&pProcessData->HandleTableLock);
if (pProcessData->Console)
{
+ RemoveEntryList(&pProcessData->ProcessEntry);
CsrReleaseObjectByPointer((Object_t *) pProcessData->Console);
}
if (pProcessData->CsrSectionViewBase)
@@ -178,14 +173,7 @@
{
NtClose(pProcessData->ServerCommunicationPort);
}
- if (pPrevProcessData)
- {
- pPrevProcessData->next = pProcessData->next;
- }
- else
- {
- ProcessData[hash] = pProcessData->next;
- }
+ *pPrevLink = pProcessData->next;
RtlFreeHeap(CsrssApiHeap, 0, pProcessData);
UNLOCK;
Modified: trunk/reactos/subsystems/win32/csrss/include/conio.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/inc…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/include/conio.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/include/conio.h [iso-8859-1] Sun Jul 27 15:08:18
2008
@@ -90,7 +90,7 @@
VOID STDCALL ConioDeleteConsole(Object_t *Object);
VOID STDCALL ConioDeleteScreenBuffer(Object_t *Buffer);
void STDCALL ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode);
-DWORD FASTCALL ConioGetBufferOffset(PCSRSS_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
+PBYTE FASTCALL ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console);
VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData);
VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event, PCSRSS_PROCESS_DATA ProcessData,
Modified: trunk/reactos/subsystems/win32/csrss/win32csr/alias.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/win32csr/alias.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/win32csr/alias.c [iso-8859-1] Sun Jul 27 15:08:18
2008
@@ -86,35 +86,20 @@
IntInsertAliasHeader(PALIAS_HEADER * RootHeader, PALIAS_HEADER NewHeader)
{
PALIAS_HEADER CurrentHeader;
- PALIAS_HEADER LastHeader = NULL;
-
- if (*RootHeader == 0)
- {
- *RootHeader = NewHeader;
- return;
- }
-
- CurrentHeader = *RootHeader;
-
- while(CurrentHeader)
+ PALIAS_HEADER *LastLink = RootHeader;
+
+ while ((CurrentHeader = *LastLink) != NULL)
{
INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName);
if (Diff < 0)
{
- if (!LastHeader)
- *RootHeader = NewHeader;
- else
- LastHeader->Next = NewHeader;
-
- NewHeader->Next = CurrentHeader;
- return;
+ break;
}
- LastHeader = CurrentHeader;
- CurrentHeader = CurrentHeader->Next;
+ LastLink = &CurrentHeader->Next;
}
- LastHeader->Next = NewHeader;
- NewHeader->Next = NULL;
+ *LastLink = NewHeader;
+ NewHeader->Next = CurrentHeader;
}
PALIAS_ENTRY
@@ -144,35 +129,20 @@
IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry)
{
PALIAS_ENTRY CurrentEntry;
- PALIAS_ENTRY LastEntry = NULL;
-
- CurrentEntry = Header->Data;
-
- if (!CurrentEntry)
- {
- Header->Data = NewEntry;
- NewEntry->Next = NULL;
- return;
- }
-
- while(CurrentEntry)
+ PALIAS_ENTRY *LastLink = &Header->Data;
+
+ while ((CurrentEntry = *LastLink) != NULL)
{
INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource);
if (Diff < 0)
{
- if (!LastEntry)
- Header->Data = NewEntry;
- else
- LastEntry->Next = NewEntry;
- NewEntry->Next = CurrentEntry;
- return;
- }
- LastEntry = CurrentEntry;
- CurrentEntry = CurrentEntry->Next;
+ break;
+ }
+ LastLink = &CurrentEntry->Next;
}
- LastEntry->Next = NewEntry;
- NewEntry->Next = NULL;
+ *LastLink = NewEntry;
+ NewEntry->Next = CurrentEntry;
}
PALIAS_ENTRY
@@ -289,28 +259,18 @@
VOID
IntDeleteAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY Entry)
{
- PALIAS_ENTRY LastEntry;
+ PALIAS_ENTRY *LastLink = &Header->Data;
PALIAS_ENTRY CurEntry;
- if (Header->Data == Entry)
- {
- Header->Data = Entry->Next;
- RtlFreeHeap(Win32CsrApiHeap, 0, Entry);
- return;
- }
- LastEntry = Header->Data;
- CurEntry = LastEntry->Next;
-
- while(CurEntry)
+ while ((CurEntry = *LastLink) != NULL)
{
if (CurEntry == Entry)
{
- LastEntry->Next = Entry->Next;
+ *LastLink = Entry->Next;
RtlFreeHeap(Win32CsrApiHeap, 0, Entry);
return;
}
- LastEntry = CurEntry;
- CurEntry = CurEntry->Next;
+ LastLink = &CurEntry->Next;
}
}
VOID
Modified: trunk/reactos/subsystems/win32/csrss/win32csr/conio.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/win32csr/conio.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/win32csr/conio.c [iso-8859-1] Sun Jul 27 15:08:18
2008
@@ -83,29 +83,23 @@
ConioConsoleCtrlEventTimeout(Event, ProcessData, 0);
}
-DWORD FASTCALL
-ConioGetBufferOffset(PCSRSS_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
-{
- return 2 * (((Y + Buff->VirtualY) % Buff->MaxY) * Buff->MaxX + X);
-}
-
-#define GET_CELL_BUFFER(b,o)\
-(b)->Buffer[(o)++]
-
-#define SET_CELL_BUFFER(b,o,c,a)\
-(b)->Buffer[(o)++]=(c),\
-(b)->Buffer[(o)++]=(a)
+PBYTE FASTCALL
+ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
+{
+ return &Buff->Buffer[2 * (((Y + Buff->VirtualY) % Buff->MaxY) *
Buff->MaxX + X)];
+}
static VOID FASTCALL
ClearLineBuffer(PCSRSS_SCREEN_BUFFER Buff)
{
- DWORD Offset = ConioGetBufferOffset(Buff, 0, Buff->CurrentY);
+ PBYTE Ptr = ConioCoordToPointer(Buff, 0, Buff->CurrentY);
UINT Pos;
for (Pos = 0; Pos < Buff->MaxX; Pos++)
{
- /* Fill the cell: Offset is incremented by the macro */
- SET_CELL_BUFFER(Buff, Offset, ' ', Buff->DefaultAttrib);
+ /* Fill the cell */
+ *Ptr++ = ' ';
+ *Ptr++ = Buff->DefaultAttrib;
}
}
@@ -433,7 +427,7 @@
CHAR *Buffer, DWORD Length, BOOL Attrib)
{
UINT i;
- DWORD Offset;
+ PBYTE Ptr;
RECT UpdateRect;
LONG CursorStartX, CursorStartY;
UINT ScrolledLines;
@@ -474,8 +468,9 @@
{
Buff->CurrentX--;
}
- Offset = ConioGetBufferOffset(Buff, Buff->CurrentX,
Buff->CurrentY);
- SET_CELL_BUFFER(Buff, Offset, ' ', Buff->DefaultAttrib);
+ Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY);
+ Ptr[0] = ' ';
+ Ptr[1] = Buff->DefaultAttrib;
UpdateRect.left = min(UpdateRect.left, (LONG) Buff->CurrentX);
UpdateRect.right = max(UpdateRect.right, (LONG) Buff->CurrentX);
}
@@ -500,12 +495,11 @@
{
EndX = Buff->MaxX;
}
- Offset = ConioGetBufferOffset(Buff, Buff->CurrentX, Buff->CurrentY);
+ Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY);
while (Buff->CurrentX < EndX)
{
- Buff->Buffer[Offset] = ' ';
- Buff->Buffer[Offset + 1] = Buff->DefaultAttrib;
- Offset += 2;
+ *Ptr++ = ' ';
+ *Ptr++ = Buff->DefaultAttrib;
Buff->CurrentX++;
}
UpdateRect.right = max(UpdateRect.right, (LONG) Buff->CurrentX - 1);
@@ -526,11 +520,11 @@
}
UpdateRect.left = min(UpdateRect.left, (LONG)Buff->CurrentX);
UpdateRect.right = max(UpdateRect.right, (LONG) Buff->CurrentX);
- Offset = ConioGetBufferOffset(Buff, Buff->CurrentX, Buff->CurrentY);
- Buff->Buffer[Offset++] = Buffer[i];
+ Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY);
+ Ptr[0] = Buffer[i];
if (Attrib)
{
- Buff->Buffer[Offset] = Buff->DefaultAttrib;
+ Ptr[1] = Buff->DefaultAttrib;
}
Buff->CurrentX++;
if (Buff->CurrentX == Buff->MaxX)
@@ -786,8 +780,8 @@
}
for (i = 0; i < Height; i++)
{
- PWORD SRow = (PWORD)&ScreenBuffer->Buffer[ConioGetBufferOffset(ScreenBuffer,
0, SY)];
- PWORD DRow = (PWORD)&ScreenBuffer->Buffer[ConioGetBufferOffset(ScreenBuffer,
0, DY)];
+ PWORD SRow = (PWORD)ConioCoordToPointer(ScreenBuffer, 0, SY);
+ PWORD DRow = (PWORD)ConioCoordToPointer(ScreenBuffer, 0, DY);
SX = SrcRegion->left;
DX = DstRegion->left;
@@ -2210,7 +2204,7 @@
COORD BufferCoord;
COORD BufferSize;
NTSTATUS Status;
- DWORD Offset;
+ PBYTE Ptr;
DWORD PSize;
DPRINT("CsrWriteConsoleOutput\n");
@@ -2270,19 +2264,20 @@
for (i = 0, Y = WriteRegion.top; Y <= WriteRegion.bottom; i++, Y++)
{
CurCharInfo = CharInfo + (i + BufferCoord.Y) * BufferSize.X + BufferCoord.X;
- Offset = ConioGetBufferOffset(Buff, WriteRegion.left, Y);
+ Ptr = ConioCoordToPointer(Buff, WriteRegion.left, Y);
for (X = WriteRegion.left; X <= WriteRegion.right; X++)
{
+ CHAR AsciiChar;
if (Request->Data.WriteConsoleOutputRequest.Unicode)
{
- CHAR AsciiChar;
ConsoleUnicodeCharToAnsiChar(Console, &AsciiChar,
&CurCharInfo->Char.UnicodeChar);
- SET_CELL_BUFFER(Buff, Offset, AsciiChar, CurCharInfo->Attributes);
}
else
{
- SET_CELL_BUFFER(Buff, Offset, CurCharInfo->Char.AsciiChar,
CurCharInfo->Attributes);
- }
+ AsciiChar = CurCharInfo->Char.AsciiChar;
+ }
+ *Ptr++ = AsciiChar;
+ *Ptr++ = CurCharInfo->Attributes;
CurCharInfo++;
}
}
@@ -2716,7 +2711,8 @@
COORD BufferCoord;
RECT ReadRegion;
RECT ScreenRect;
- DWORD i, Offset;
+ DWORD i;
+ PBYTE Ptr;
LONG X, Y;
UINT CodePage;
@@ -2769,20 +2765,20 @@
{
CurCharInfo = CharInfo + (i * BufferSize.X);
- Offset = ConioGetBufferOffset(Buff, ReadRegion.left, Y);
+ Ptr = ConioCoordToPointer(Buff, ReadRegion.left, Y);
for (X = ReadRegion.left; X < ReadRegion.right; ++X)
{
if (Request->Data.ReadConsoleOutputRequest.Unicode)
{
MultiByteToWideChar(CodePage, 0,
- (PCHAR)&GET_CELL_BUFFER(Buff, Offset), 1,
+ (PCHAR)Ptr++, 1,
&CurCharInfo->Char.UnicodeChar, 1);
}
else
{
- CurCharInfo->Char.AsciiChar = GET_CELL_BUFFER(Buff, Offset);
- }
- CurCharInfo->Attributes = GET_CELL_BUFFER(Buff, Offset);
+ CurCharInfo->Char.AsciiChar = *Ptr++;
+ }
+ CurCharInfo->Attributes = *Ptr++;
++CurCharInfo;
}
}
Modified: trunk/reactos/subsystems/win32/csrss/win32csr/guiconsole.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/win32csr/guiconsole.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/win32csr/guiconsole.c [iso-8859-1] Sun Jul 27
15:08:18 2008
@@ -880,7 +880,7 @@
for (Line = TopLine; Line <= BottomLine; Line++)
{
- From = Buff->Buffer + ConioGetBufferOffset(Buff, LeftChar, Line);
+ From = ConioCoordToPointer(Buff, LeftChar, Line);
Start = LeftChar;
To = GuiData->LineBuffer;
@@ -934,7 +934,7 @@
{
CursorHeight = 1;
}
- From = Buff->Buffer + ConioGetBufferOffset(Buff, Buff->CurrentX,
Buff->CurrentY) + 1;
+ From = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY) + 1;
if (*From != DEFAULT_ATTRIB)
{
Modified: trunk/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/win…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c [iso-8859-1] Sun Jul 27
15:08:18 2008
@@ -86,7 +86,7 @@
LONG i;
PBYTE Src, SrcEnd;
- Src = Buff->Buffer + ConioGetBufferOffset(Buff, Region->left, Region->top);
+ Src = ConioCoordToPointer(Buff, Region->left, Region->top);
SrcDelta = Buff->MaxX * 2;
SrcEnd = Buff->Buffer + Buff->MaxY * Buff->MaxX * 2;
DestDelta = ConioRectWidth(Region) * 2;