mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
reference: StreamGetSzPtr
git-svn-id: svn://ultimatepp.org/upp/trunk@8301 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
93a4d463a1
commit
ba970ec6da
4 changed files with 77 additions and 1 deletions
|
|
@ -37,7 +37,7 @@ const char *examples[] = {
|
|||
"{{1:1:1|2 A1::-2 A2:: A3:: B1:: B2:: B3}}",
|
||||
"{{1:2 A1:: A2:: B1:: {{1:2 a1:: a2:: a1:: a2}}}}",
|
||||
"{{1~a30/50o Round border}}",
|
||||
NULL
|
||||
NULL
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
|
|
|
|||
61
reference/StreamGetSzPtr/StreamGetSzPtr.cpp
Normal file
61
reference/StreamGetSzPtr/StreamGetSzPtr.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
int CountLines(Stream& s)
|
||||
{
|
||||
int n = 0;
|
||||
int c;
|
||||
while((c = s.Get()) >= 0)
|
||||
n += c == '\n';
|
||||
return n;
|
||||
}
|
||||
|
||||
int CountLinesOptimized(Stream& s)
|
||||
{
|
||||
int n = 0;
|
||||
for(;;) {
|
||||
int sz;
|
||||
const byte *p = s.GetSzPtr(sz);
|
||||
if(sz) {
|
||||
const byte *e = p + sz;
|
||||
const byte *e4 = p + (sz & ~3);
|
||||
while(p < e4) {
|
||||
n += (p[0] == '\n' || p[1] == '\n' || p[2] == '\n' || p[3] == '\n');
|
||||
p += 4;
|
||||
}
|
||||
while(p < e)
|
||||
n += *p++ == '\n';
|
||||
}
|
||||
else {
|
||||
int c = s.Get();
|
||||
if(c < 0)
|
||||
return n;
|
||||
n += c == '\n';
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_FILE|LOG_COUT);
|
||||
|
||||
const Vector<String>& arg = CommandLine();
|
||||
if(arg.GetCount() == 0) {
|
||||
RLOG("Please provide testing file path as argument, preferably >500MB");
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
RTIMESTOP("Simple");
|
||||
FileIn in(arg[0]);
|
||||
RDUMP(CountLines(in));
|
||||
}
|
||||
|
||||
{
|
||||
RTIMESTOP("Optimized");
|
||||
FileIn in(arg[0]);
|
||||
RDUMP(CountLinesOptimized(in));
|
||||
}
|
||||
}
|
||||
11
reference/StreamGetSzPtr/StreamGetSzPtr.upp
Normal file
11
reference/StreamGetSzPtr/StreamGetSzPtr.upp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
description "Using Stream::GetSzPtr to optimize the algorithm to count lines in Stream\377";
|
||||
|
||||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
StreamGetSzPtr.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2";
|
||||
|
||||
4
reference/StreamGetSzPtr/init
Normal file
4
reference/StreamGetSzPtr/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _StreamGetSzPtr_icpp_init_stub
|
||||
#define _StreamGetSzPtr_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue