Небольшая оптимизация с #2401

This commit is contained in:
Mikhalkovich Stanislav 2021-01-11 00:09:28 +03:00
parent 07df31f762
commit b79bcd904e
10 changed files with 55 additions and 25 deletions

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "7";
public const string Build = "1";
public const string Revision = "2794";
public const string Revision = "2796";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%COREVERSION%=1
%REVISION%=2794
%REVISION%=2796
%MINOR%=7
%MAJOR%=3

View file

@ -1 +1 @@
3.7.1.2794
3.7.1.2796

View file

@ -1 +1 @@
!define VERSION '3.7.1.2794'
!define VERSION '3.7.1.2796'

View file

@ -1882,10 +1882,10 @@ function Length(s: string): integer;
procedure SetLength(var s: string; n: integer);
///--
procedure SetLengthForShortString(var s: string; n, sz: integer);
/// Вставляет подстроку source в строку s с позиции index
procedure Insert(source: string; var s: string; index: integer);
/// Вставляет подстроку subs в строку s с позиции index
procedure Insert(subs: string; var s: string; index: integer);
///--
procedure InsertInShortString(source: string; var s: string; index, n: integer);
procedure InsertInShortString(subs: string; var s: string; index, n: integer);
/// Удаляет из строки s count символов с позиции index
procedure Delete(var s: string; index, count: integer);
/// Возвращает подстроку строки s длины count с позиции index
@ -8842,27 +8842,27 @@ begin
s += new String(' ', sz - s.Length)
end;
procedure Insert(source: string; var s: string; index: integer);
procedure Insert(subs: string; var s: string; index: integer);
// Insert никогда не возвращает исключения
begin
if index < 1 then
index := 1;
if index > s.Length + 1 then
index := s.Length + 1;
s := s.Insert(index - 1, source);
s := s.Insert(index - 1, subs);
end;
procedure InsertInShortString(source: string; var s: string; index, n: integer);
procedure InsertInShortString(subs: string; var s: string; index, n: integer);
begin
if index < 1 then
index := 1;
if index > n then
exit;
try
s := s.Insert(index - 1, source);
s := s.Insert(index - 1, subs);
if s.Length > n then s := s.Substring(0, n);
except
s := s.Insert(s.Length, source);
s := s.Insert(s.Length, subs);
if s.Length > n then s := s.Substring(0, n);
end;
end;

12
TestSuite/fResult2.pas Normal file
View file

@ -0,0 +1,12 @@
function Sum(a,b: integer): integer;
begin
var Sum := 0;
for var i:=a to b do
begin
Sum := Sum + i;
end;
end;
begin
Assert(Sum(1,10)=0);
end.

15
TestSuite/fResult3.pas Normal file
View file

@ -0,0 +1,15 @@
procedure p;
function Sum(a,b: integer): integer;
begin
var Sum := 0;
Sum := 666;
end;
begin
Assert(Sum(1,10)=0);
end;
begin
p;
end.

View file

@ -1871,7 +1871,7 @@ namespace PascalABCCompiler.TreeConverter
mc = method_compare.greater_method;
}
}
if (mc == method_compare.greater_method)
if (mc == method_compare.greater_method) // f[i]>f[j] - значит, удалять надо f[i], а в коде наоборот!!! Странно...
{
tcll.remove_at(j);
set_of_possible_functions.RemoveAt(j);

View file

@ -17056,11 +17056,14 @@ namespace PascalABCCompiler.TreeConverter
if (sil == null)
{
int comp = SystemLibrary.SystemLibrary.string_comparer.Compare(_ident.name, context.top_function.name);
List<SymbolInfo> mysi = context.find(_ident.name);
if (comp == 0 && mysi != null && mysi[0].sym_info is function_node) // мы нашли функцию и ее имя совпадает с ident
if (comp == 0) // мы нашли функцию и ее имя совпадает с ident
{
local_variable lv = context.top_function.return_variable;
return new local_variable_reference(lv, 0, get_location(_ident));
List<SymbolInfo> mysi = context.find(_ident.name);
if (mysi != null && mysi[0].sym_info is function_node)
{
local_variable lv = context.top_function.return_variable;
return new local_variable_reference(lv, 0, get_location(_ident));
}
}
}
}

View file

@ -1882,10 +1882,10 @@ function Length(s: string): integer;
procedure SetLength(var s: string; n: integer);
///--
procedure SetLengthForShortString(var s: string; n, sz: integer);
/// Вставляет подстроку source в строку s с позиции index
procedure Insert(source: string; var s: string; index: integer);
/// Вставляет подстроку subs в строку s с позиции index
procedure Insert(subs: string; var s: string; index: integer);
///--
procedure InsertInShortString(source: string; var s: string; index, n: integer);
procedure InsertInShortString(subs: string; var s: string; index, n: integer);
/// Удаляет из строки s count символов с позиции index
procedure Delete(var s: string; index, count: integer);
/// Возвращает подстроку строки s длины count с позиции index
@ -8842,27 +8842,27 @@ begin
s += new String(' ', sz - s.Length)
end;
procedure Insert(source: string; var s: string; index: integer);
procedure Insert(subs: string; var s: string; index: integer);
// Insert никогда не возвращает исключения
begin
if index < 1 then
index := 1;
if index > s.Length + 1 then
index := s.Length + 1;
s := s.Insert(index - 1, source);
s := s.Insert(index - 1, subs);
end;
procedure InsertInShortString(source: string; var s: string; index, n: integer);
procedure InsertInShortString(subs: string; var s: string; index, n: integer);
begin
if index < 1 then
index := 1;
if index > n then
exit;
try
s := s.Insert(index - 1, source);
s := s.Insert(index - 1, subs);
if s.Length > n then s := s.Substring(0, n);
except
s := s.Insert(s.Length, source);
s := s.Insert(s.Length, subs);
if s.Length > n then s := s.Substring(0, n);
end;
end;