ошибка [E0106]: отсутствует указатель времени жизни (несмотря на то, что он установлен) [duplicate]

ok, я подведу итог:

Тестовый код:

package com.stackoverflow.test;

import java.net.URI;
import java.net.URISyntaxException;

public class TestOfRemovingParameteresFromString {
  private final static int NUMBER_OF_ITERATIONS = 1000000;
  private final static String TEST_URL_SRTRING = "http://www.xyz/path1/path2/path3?param1=value1&param2=value2";

  private static String getUrlWithoutParameters(String url) throws URISyntaxException {
    URI uri = new URI(url);
    return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()).toString();
  }

  public static void main(String[] args) throws URISyntaxException {
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
      String result = TEST_URL_SRTRING.split("\\?")[0];
    }
    System.out.println("Result=" + (System.currentTimeMillis() - startTime));
    startTime = System.currentTimeMillis();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
      String result = TEST_URL_SRTRING.substring(0, TEST_URL_SRTRING.indexOf("?"));
    }
    System.out.println("Result=" + (System.currentTimeMillis() - startTime));
    startTime = System.currentTimeMillis();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
      String result = TEST_URL_SRTRING.substring(0, TEST_URL_SRTRING.indexOf('?'));
    }
    System.out.println("Result=" + (System.currentTimeMillis() - startTime));
    startTime = System.currentTimeMillis();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
      String result = TEST_URL_SRTRING.substring(0, TEST_URL_SRTRING.lastIndexOf('?'));
    }       
    System.out.println("Result=" + (System.currentTimeMillis() - startTime));
    startTime = System.currentTimeMillis();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
      String result = TEST_URL_SRTRING.replaceFirst("\\?.*$", "");
    }
    System.out.println("Result=" + (System.currentTimeMillis() - startTime));
    startTime = System.currentTimeMillis();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
      String result = getUrlWithoutParameters(TEST_URL_SRTRING);
    }
    System.out.println("Result=" + (System.currentTimeMillis() - startTime));

  }
}

Выход:

Результат = 353

Результат = 54

Результат = 29

Результат = 37

Результат = 1086

Результат = 1647

Итак, самый быстрый из них третий:

    startTime = System.currentTimeMillis();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
      String result = TEST_URL_SRTRING.substring(0, TEST_URL_SRTRING.indexOf('?'));
    }
    System.out.println("Result=" + (System.currentTimeMillis() - startTime));
1
задан Tim Diekmann 16 January 2019 в 13:27
поделиться

1 ответ

Я получил ответ на IRC-канале # rust-beginners:

13:10:17 drager | d33tah: я подозреваю, что ArgMatches действительно хочет время жизни, поэтому ArgMatches < 'static> в этом случае

Итак, решение было изменить сигнатуру функции на:

fn parse_argv() -> clap::ArgMatches<'static> {
0
ответ дан d33tah 16 January 2019 в 13:27
поделиться
Другие вопросы по тегам:

Похожие вопросы: