小编tim*_*m93的帖子

在同一语句中使用shift和@_是否安全?

以下代码是否安全?它是否运行在所有perl版本> = 5.8?是否保证在解压缩@_之前执行转换

sub f1 {
    shift->update(p1 => shift, p2 => shift, @_);
}
Run Code Online (Sandbox Code Playgroud)

详细替代代码:

sub f2 {
    my ($self, $p1, $p2, @r) = @_;
    $self->update(p1 => $p1, p2 => $p2, @r);
}
Run Code Online (Sandbox Code Playgroud)

parameters perl unpack shift

3
推荐指数
1
解决办法
69
查看次数

delphi子串计数性能

我有一些函数来计算由空格分隔的字符串中的子字符串:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses System.SysUtils,windows;

//s=string to search in
//t=string to search for
//cs=delimiters

function f0(const s,t:string;const cs:tsyscharset):integer;
var
  p,q:pchar;
  u:string;
begin
  result:=0;
  p:=pointer(s);
  if p<>nil then
    while p^<>#0 do
    begin
      while (p^<>#0) and charinset(p^,cs) do inc(p);
      q:=p;
      while (p^<>#0) and not charinset(p^,cs) do inc(p);
      if p>q then
      begin
        setstring(u,q,p-q);
        //writeln('[',u,']');
        if u=t then inc(result);
      end;
    end;
end;

function f1(const s,t:string;const cs:tsyscharset):integer;
var
  i,j,l:integer;
  u:string;
begin
  result:=0;
  l:=length(s);
  i:=1;
  while i<=l do
  begin
    while (i<=l) and …
Run Code Online (Sandbox Code Playgroud)

delphi string performance substring delphi-xe2

0
推荐指数
1
解决办法
805
查看次数

标签 统计

delphi ×1

delphi-xe2 ×1

parameters ×1

performance ×1

perl ×1

shift ×1

string ×1

substring ×1

unpack ×1